Skip to content

Test: wait for network changes in TestNetworkDBNodeJoinLeaveIteration#42829

Merged
thaJeztah merged 1 commit into
moby:masterfrom
zq-david-wang:testfix_TestNetworkDBNodeJoinLeaveIteration
Jul 22, 2022
Merged

Test: wait for network changes in TestNetworkDBNodeJoinLeaveIteration#42829
thaJeztah merged 1 commit into
moby:masterfrom
zq-david-wang:testfix_TestNetworkDBNodeJoinLeaveIteration

Conversation

@zq-david-wang

Copy link
Copy Markdown
Contributor

Signed-off-by: David Wang [email protected]

fix #42698
In network node change test, the expected behavior is focused on how many nodes left in networkDB, besides timing issues, things would also go tricky for a leave-then-join sequence, if the check (counting the nodes) happened before the first "leave" event, then the testcase actually miss its target and report PASS without verifying its final result; if the check happened after the 'leave' event, but before the 'join' event, the test would report FAIL unnecessary;

This code change would check both the db changes and the node count, it would report PASS only when networkdb has indeed changed and the node count is expected

@thaJeztah

Copy link
Copy Markdown
Member

Thanks for contributing @zq-david-wang - and apologies for the long delay; I was trying to get more eyes on this fix, but it slipped off my radar. Let me try to get some eyes on this one.

I did a quick rebase of your PR to make CI run again, and I included your description from GitHub in the commit message (which can be useful when looking through git history).

Comment thread libnetwork/networkdb/networkdb_test.go Outdated
nntime, ncount := db.networkClock.Time(), 0
for i := 0; i < maxRetries; i++ {
nntime, ncount = db.networkClock.Time(), 0
if nodes, ok := db.networkNodes[network]; ok {

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.

Does this map access need to be done in a critical section? I see there's an RWMutex embedded in the NetworkDB struct, and application code only accesses the networkNodes map while holding the lock.

Comment thread libnetwork/networkdb/networkdb_test.go Outdated
t.Errorf("%v(%v): Node existence verification for node %s failed", db.config.Hostname, db.config.NodeID, node)
}

func (db *NetworkDB) witnessNetworkNodeChanges(t *testing.T, ntime serf.LamportTime, network string, count int) bool {

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.

Suggested change
func (db *NetworkDB) witnessNetworkNodeChanges(t *testing.T, ntime serf.LamportTime, network string, count int) bool {
func (db *NetworkDB) witnessNetworkNodeChanges(t *testing.T, ntime serf.LamportTime, network string, count int) bool {
t.Helper()

Comment thread libnetwork/networkdb/networkdb_test.go Outdated
if nntime != ntime && ncount == count {
return true
}
time.Sleep(sleepInterval)

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.

Have you considered using poll.WaitOn instead of hand-rolling a polling loop?

@thaJeztah

Copy link
Copy Markdown
Member

Ah, wrong tab; sorry

@zq-david-wang
zq-david-wang force-pushed the testfix_TestNetworkDBNodeJoinLeaveIteration branch from 191f5bc to 63c88ef Compare July 21, 2022 14:46
@zq-david-wang

Copy link
Copy Markdown
Contributor Author

@thaJeztah I am not sure whether this PR is still necessary, after such a long period, any recent random failure for this test case?
Any way, I make some adjustment base on @corhere comments.

It is ok for me to close this if the PR is not needed anymore, otherwise @corhere , could you help review the new code, thx~

In network node change test, the expected behavior is focused on how many nodes
left in networkDB, besides timing issues, things would also go tricky for a
leave-then-join sequence, if the check (counting the nodes) happened before the
first "leave" event, then the testcase actually miss its target and report PASS
without verifying its final result; if the check happened after the 'leave' event,
but before the 'join' event, the test would report FAIL unnecessary;

This code change would check both the db changes and the node count, it would
report PASS only when networkdb has indeed changed and the node count is expected.

Signed-off-by: David Wang <[email protected]>
@zq-david-wang
zq-david-wang force-pushed the testfix_TestNetworkDBNodeJoinLeaveIteration branch from 63c88ef to f499c6b Compare July 21, 2022 14:57
@thaJeztah

Copy link
Copy Markdown
Member

I think the test was still flaky (at least to some extend), and (IIRC) mostly waiting for the suggestions to be addressed; so thanks for updating it!

@corhere ptal

@thaJeztah thaJeztah left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

Comment on lines +483 to +489
var (
dbIndex int32
staleNetworkTime [2]serf.LamportTime
expectNodeCount int
network = "network1"
)
dbChangeWitness := func(t poll.LogT) poll.Result {

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.

Those variables are functionally arguments to the dbChangeWitness poll check function. It would be a lot clearer if they were actually passed in as function arguments rather than by mutating variables.

Suggested change
var (
dbIndex int32
staleNetworkTime [2]serf.LamportTime
expectNodeCount int
network = "network1"
)
dbChangeWitness := func(t poll.LogT) poll.Result {
dbChangeWitness := func(
dbIndex int32,
staleNetworkTime [2]serf.LamportTime,
expectNodeCount int,
network string,
) poll.Check {
return func(t poll.LogT) poll.Result {

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.

This can be addressed in a follow-up PR since it's all private to the one test

@thaJeztah thaJeztah modified the milestones: 22.06.0, v-next Jul 22, 2022
@thaJeztah

Copy link
Copy Markdown
Member

Thanks! Let's get this one in 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Flaky test: TestNetworkDBNodeJoinLeaveIteration

3 participants