Skip to content

Commit

Permalink
tests: replace assert.Eventually with a simpler function
Browse files Browse the repository at this point in the history
race test cases fail, on travis, for macOS in assert.Eventually
  • Loading branch information
drakkan committed Mar 16, 2020
1 parent 083e69c commit 8bb09a0
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions server_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -470,21 +470,35 @@ func runSftpClient(t *testing.T, script string, path string, host string, port i
return stdout.String(), err
}

// assert.Eventually seems to have a data rate on macOS with go 1.14 so replace it with this simpler function
func waitForCondition(t *testing.T, condition func() bool) {
start := time.Now()
tick := 10 * time.Millisecond
waitFor := 100 * time.Millisecond
for !condition() {
time.Sleep(tick)
if time.Since(start) > waitFor {
break
}
}
assert.True(t, condition())
}

func checkAllocatorBeforeServerClose(t *testing.T, alloc *allocator) {
if alloc != nil {
// before closing the server we are, generally, waiting for new packets in recvPacket and we have a page allocated.
// Sometime the sendPacket returns some milliseconds after the client receives the response, and so we have 2
// allocated pages here, so wait some milliseconds. To avoid crashes we must be sure to not release the pages
// too soon.
assert.Eventually(t, func() bool { return alloc.countUsedPages() <= 1 }, 100*time.Millisecond, 15*time.Millisecond)
waitForCondition(t, func() bool { return alloc.countUsedPages() <= 1 })
}
}

func checkAllocatorAfterServerClose(t *testing.T, alloc *allocator) {
if alloc != nil {
// wait for the server cleanup
assert.Eventually(t, func() bool { return alloc.countUsedPages() == 0 }, 100*time.Millisecond, 15*time.Millisecond)
assert.Eventually(t, func() bool { return alloc.countAvailablePages() == 0 }, 100*time.Millisecond, 15*time.Millisecond)
waitForCondition(t, func() bool { return alloc.countUsedPages() == 0 })
waitForCondition(t, func() bool { return alloc.countAvailablePages() == 0 })
}
}

Expand Down

0 comments on commit 8bb09a0

Please sign in to comment.