-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Shuffle seed brokers so we don't always connect to the first one provided #441
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -375,25 +375,33 @@ func TestClientRefreshBehaviour(t *testing.T) { | |
} | ||
|
||
func TestClientResurrectDeadSeeds(t *testing.T) { | ||
seed1 := newMockBroker(t, 1) | ||
seed2 := newMockBroker(t, 2) | ||
seed3 := newMockBroker(t, 3) | ||
addr1 := seed1.Addr() | ||
addr2 := seed2.Addr() | ||
addr3 := seed3.Addr() | ||
|
||
initialSeed := newMockBroker(t, 0) | ||
emptyMetadata := new(MetadataResponse) | ||
seed1.Returns(emptyMetadata) | ||
initialSeed.Returns(emptyMetadata) | ||
|
||
conf := NewConfig() | ||
conf.Metadata.Retry.Backoff = 0 | ||
conf.Metadata.RefreshFrequency = 0 | ||
c, err := NewClient([]string{addr1, addr2, addr3}, conf) | ||
c, err := NewClient([]string{initialSeed.Addr()}, conf) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
initialSeed.Close() | ||
|
||
client := c.(*client) | ||
|
||
seed1 := newMockBroker(t, 1) | ||
seed2 := newMockBroker(t, 2) | ||
seed3 := newMockBroker(t, 3) | ||
addr1 := seed1.Addr() | ||
addr2 := seed2.Addr() | ||
addr3 := seed3.Addr() | ||
|
||
// Overwrite the seed brokers with a fixed ordering to make this test deterministic. | ||
safeClose(t, client.seedBrokers[0]) | ||
client.seedBrokers = []*Broker{NewBroker(addr1), NewBroker(addr2), NewBroker(addr3)} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. rather than completely overriding it, just append the two new ones is simpler There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I feel this is simpler to understand, because now you can basically ignore what happened before; the seed broker state is complete defined here. YMMV. |
||
client.deadSeeds = []*Broker{} | ||
|
||
wg := sync.WaitGroup{} | ||
wg.Add(1) | ||
go func() { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can't you just create a goroutine that waits until
NewClient
is blocked, then reads off the seed order from the client and returns metadata to the first broker on that list?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe, but I find this way simpler and easier to understand. The
RefreshMetadata
call is what is being tested, not theNewClient
call.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the current version leaks a broker goroutine, doesn't it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed that.