Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 5 additions & 11 deletions br/pkg/restore/import_mode_switcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ package restore_test

import (
"context"
"fmt"
"net"
"sync"
"testing"
Expand Down Expand Up @@ -50,17 +49,12 @@ func (s *mockImportServer) SwitchMode(_ context.Context, req *import_sstpb.Switc

func TestRestorePreWork(t *testing.T) {
ctx := context.Background()
var port int
var lis net.Listener
var err error
for port = 0; port < 1000; port += 1 {
addr := fmt.Sprintf(":%d", 51111+port)
lis, err = net.Listen("tcp", addr)
if err == nil {
break
}
t.Log(err)
}
addr := ":0"
lis, err = net.Listen("tcp", addr)
t.Log(err)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated.

addr = lis.Addr().String()

s := grpc.NewServer()
ch := make(chan struct{})
Expand All @@ -77,7 +71,7 @@ func TestRestorePreWork(t *testing.T) {
pdClient := split.NewFakePDClient([]*metapb.Store{
{
Id: 1,
Address: fmt.Sprintf(":%d", 51111+port),
Address: addr,
},
}, false, nil)
pdHTTPCli := split.NewFakePDHTTPClient()
Expand Down
17 changes: 5 additions & 12 deletions br/pkg/restore/internal/import_client/import_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ package importclient_test

import (
"context"
"fmt"
"net"
"sync"
"testing"
Expand Down Expand Up @@ -79,18 +78,12 @@ func (s *mockImportServer) MultiIngest(_ context.Context, req *import_sstpb.Mult

func TestImportClient(t *testing.T) {
ctx := context.Background()
var port int
var lis net.Listener
var err error
for port = 0; port < 1000; port += 1 {
addr := fmt.Sprintf(":%d", 51111+port)
lis, err = net.Listen("tcp", addr)
if err == nil {
break
}
t.Log(err)
}

addr := ":0"
lis, err = net.Listen("tcp", addr)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we have used a library freeport.GetFreePort()

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's also an option, but if it can be accomplished using only the official libraries, it's better not to introduce third-party libraries.

t.Log(err)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should use require.NoError?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated.

addr = lis.Addr().String()
s := grpc.NewServer()
import_sstpb.RegisterImportSSTServer(s, &mockImportServer{ErrCount: 3})

Expand All @@ -102,7 +95,7 @@ func TestImportClient(t *testing.T) {
require.NoError(t, err)
}()

client := importclient.NewImportClient(&storeClient{addr: fmt.Sprintf(":%d", 51111+port)}, nil, keepalive.ClientParameters{})
client := importclient.NewImportClient(&storeClient{addr: addr}, nil, keepalive.ClientParameters{})

{
resp, err := client.ClearFiles(ctx, 1, &import_sstpb.ClearRequest{Prefix: "test"})
Expand Down
Loading