Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
39 changes: 13 additions & 26 deletions experimental/ssh/internal/fuse/keepalive_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,12 @@ func TestKeepRegistered(t *testing.T) {
initialRequests := len(requests)
failure = ""
mu.Unlock()
time.Sleep(59 * time.Second)
synctest.Wait()
synctest.Sleep(59 * time.Second)
mu.Lock()
assert.Len(t, requests, initialRequests)
assert.Equal(t, 1, tokenCalls)
mu.Unlock()
time.Sleep(time.Second)
synctest.Wait()
synctest.Sleep(time.Second)
mu.Lock()
refreshes := 1
switch initialFailure {
Expand All @@ -88,8 +86,7 @@ func TestKeepRegistered(t *testing.T) {

before := len(requests)
mu.Unlock()
time.Sleep(3 * fuse.RefreshInterval)
synctest.Wait()
synctest.Sleep(3 * fuse.RefreshInterval)
mu.Lock()
assert.Len(t, requests, before+3, "steady state must only refresh volumes")
for _, req := range requests[before:] {
Expand All @@ -99,24 +96,21 @@ func TestKeepRegistered(t *testing.T) {

token = "token-two"
mu.Unlock()
time.Sleep(fuse.RefreshInterval)
synctest.Wait()
synctest.Sleep(fuse.RefreshInterval)
mu.Lock()
require.Len(t, requests, before+2)
assert.Equal(t, token, requests[before].Body["apiToken"])
assert.Equal(t, token, requests[before+1].Body["apiToken"])

pid = registration.PID - 1
mu.Unlock()
time.Sleep(fuse.RefreshInterval)
synctest.Wait()
synctest.Sleep(fuse.RefreshInterval)
mu.Lock()
assert.Len(t, requests, before+4, "restore registration when a different ancestor is reported")
pid = registration.PID
probeErr = errors.New("filesystem metadata unavailable")
mu.Unlock()
time.Sleep(fuse.RefreshInterval)
synctest.Wait()
synctest.Sleep(fuse.RefreshInterval)
mu.Lock()
assert.Len(t, requests, before+6, "restore registration when the probe fails")
probeErr = nil
Expand All @@ -126,8 +120,7 @@ func TestKeepRegistered(t *testing.T) {
mu.Lock()
callsAtCancel := tokenCalls
mu.Unlock()
time.Sleep(2 * fuse.RefreshInterval)
synctest.Wait()
synctest.Sleep(2 * fuse.RefreshInterval)
mu.Lock()
assert.Equal(t, callsAtCancel, tokenCalls)
assert.Len(t, requests, before+6)
Expand Down Expand Up @@ -165,8 +158,7 @@ func TestKeepRegisteredRecoversVolumesRegistrationLoss(t *testing.T) {
// A UC-FUSE restart loses its mapping while WSFS still reports the server PID.
registered["1015"] = false
mu.Unlock()
time.Sleep(fuse.RefreshInterval)
synctest.Wait()
synctest.Sleep(fuse.RefreshInterval)
mu.Lock()
assert.True(t, registered["1015"], "restore volumes registration with an unchanged credential")
assert.Equal(t, 1, requests["1021"], "healthy WSFS must not invalidate its caches")
Expand Down Expand Up @@ -225,13 +217,11 @@ func TestKeepRegisteredBlockedPIDProbe(t *testing.T) {
synctest.Wait()
start := time.Now()
for tick := range 3 {
time.Sleep(time.Until(start.Add(time.Duration(tick+1) * fuse.RefreshInterval)))
synctest.Wait()
synctest.Sleep(time.Until(start.Add(time.Duration(tick+1) * fuse.RefreshInterval)))
mu.Lock()
assert.Equal(t, tick+1, requests["1015"], "wait for the probe before refreshing")
mu.Unlock()
time.Sleep(fuse.PIDProbeTimeout)
synctest.Wait()
synctest.Sleep(fuse.PIDProbeTimeout)
mu.Lock()
assert.Equal(t, tick+2, requests["1015"], "keep refreshing volumes while WSFS is blocked")
assert.Equal(t, tick+2, requests["1021"], "force WSFS registration after a probe timeout")
Expand All @@ -242,16 +232,14 @@ func TestKeepRegisteredBlockedPIDProbe(t *testing.T) {
if scenario == "recover" {
releaseProbe <- struct{}{}
synctest.Wait()
time.Sleep(2 * fuse.RefreshInterval)
synctest.Wait()
synctest.Sleep(2 * fuse.RefreshInterval)
mu.Lock()
assert.Equal(t, 6, requests["1015"])
assert.Equal(t, 4, requests["1021"], "stop forcing WSFS registration after probe recovery")
assert.Equal(t, 2, probeCalls, "resume probing after the outstanding read completes")
mu.Unlock()
} else {
time.Sleep(fuse.RefreshInterval - fuse.PIDProbeTimeout)
synctest.Wait()
synctest.Sleep(fuse.RefreshInterval - fuse.PIDProbeTimeout)
}

cancel()
Expand All @@ -265,8 +253,7 @@ func TestKeepRegisteredBlockedPIDProbe(t *testing.T) {
callsAtCancel := probeCalls
requestsAtCancel := requests["1015"]
mu.Unlock()
time.Sleep(2 * fuse.RefreshInterval)
synctest.Wait()
synctest.Sleep(2 * fuse.RefreshInterval)
mu.Lock()
assert.Equal(t, callsAtCancel, probeCalls)
assert.Equal(t, requestsAtCancel, requests["1015"])
Expand Down
3 changes: 1 addition & 2 deletions experimental/ssh/internal/proxy/connections_idle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ func TestConnectionsManagerExtendIdleTimeout(t *testing.T) {
assert.True(t, <-connections.TimedOut)
require.True(t, connections.TryAdd("connected", nil))
connections.ExtendIdleTimeout(time.Second)
time.Sleep(time.Minute)
synctest.Wait()
synctest.Sleep(time.Minute)
select {
case <-connections.TimedOut:
t.Fatal("extended timeout fired while a client was connected")
Expand Down
15 changes: 5 additions & 10 deletions experimental/ssh/internal/proxy/connections_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,7 @@ func TestConnectionsManager_ShutdownTimer_TriggersOnEmptyConnections(t *testing.
case <-time.After(time.Hour):
}
}()
time.Sleep(time.Hour)
synctest.Wait()
synctest.Sleep(time.Hour)
assert.True(t, timedOut, "Expected timeout signal but didn't receive one")
})
}
Expand All @@ -170,8 +169,7 @@ func TestConnectionsManager_ShutdownTimer_CancelledWhenConnectionAdded(t *testin
result := cm.TryAdd("test-id", conn)
require.True(t, result)

time.Sleep(time.Hour)
synctest.Wait()
synctest.Sleep(time.Hour)
assert.False(t, timedOut, "Unexpected timeout signal while connection exists")
})
}
Expand All @@ -194,8 +192,7 @@ func TestConnectionsManager_ShutdownTimer_RestartsWhenLastConnectionRemoved(t *t
require.True(t, result)

// Wait a bit to ensure timer would have triggered if not cancelled
time.Sleep(time.Hour)
synctest.Wait()
synctest.Sleep(time.Hour)
assert.False(t, timedOut, "Unexpected timeout signal while connection exists")

// Setup new goroutine to listen for timeout signal
Expand All @@ -209,8 +206,7 @@ func TestConnectionsManager_ShutdownTimer_RestartsWhenLastConnectionRemoved(t *t
}()
// Remove connection - should restart shutdown timer
cm.Remove("test-id")
time.Sleep(time.Hour)
synctest.Wait()
synctest.Sleep(time.Hour)
assert.True(t, timedOut, "Expected timeout signal after last connection removed but didn't receive one")
})
}
Expand Down Expand Up @@ -239,8 +235,7 @@ func TestConnectionsManager_ShutdownTimer_NoRestartWhenConnectionsRemain(t *test
cm.Remove("conn1")
assert.Equal(t, 1, cm.Count())

time.Sleep(time.Hour)
synctest.Wait()
synctest.Sleep(time.Hour)
assert.False(t, timedOut, "Unexpected timeout signal while connections still exist")
})
}
21 changes: 7 additions & 14 deletions experimental/ssh/internal/server/idle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ func TestWaitForIdleShutdown(t *testing.T) {
go func() {
shutdown <- server.WaitForIdleShutdown(ctx, connections, test.keepDetached, root, server.TestServerPid)
}()
time.Sleep(time.Second + 2*server.DetachedProcessCheckInterval)
synctest.Wait()
synctest.Sleep(time.Second + 2*server.DetachedProcessCheckInterval)
assert.Equal(t, !test.wantHold, len(shutdown) > 0)
require.True(t, connections.TryAdd("cleanup", nil))
cancel()
Expand All @@ -75,12 +74,10 @@ func TestWaitForIdleShutdownWhenDetachedWorkFinishes(t *testing.T) {
go func() {
shutdown <- server.WaitForIdleShutdown(t.Context(), connections, true, root, server.TestServerPid)
}()
time.Sleep(shutdownDelay)
synctest.Wait()
synctest.Sleep(shutdownDelay)
require.Empty(t, shutdown)
require.NoError(t, os.RemoveAll(filepath.Join(root, detachedProcessDirectory)))
time.Sleep(server.DetachedProcessCheckInterval)
synctest.Wait()
synctest.Sleep(server.DetachedProcessCheckInterval)
require.Len(t, shutdown, 1)
assert.NoError(t, <-shutdown)
})
Expand All @@ -99,20 +96,16 @@ func TestWaitForIdleShutdownReconnect(t *testing.T) {
go func() {
shutdown <- server.WaitForIdleShutdown(t.Context(), connections, true, root, server.TestServerPid)
}()
time.Sleep(shutdownDelay)
synctest.Wait()
synctest.Sleep(shutdownDelay)
require.Empty(t, shutdown)
require.True(t, connections.TryAdd("reconnected", nil))
require.NoError(t, os.RemoveAll(filepath.Join(root, detachedProcessDirectory)))
time.Sleep(connectedFor)
synctest.Wait()
synctest.Sleep(connectedFor)
require.Empty(t, shutdown)
connections.Remove("reconnected")
time.Sleep(shutdownDelay - time.Second)
synctest.Wait()
synctest.Sleep(shutdownDelay - time.Second)
require.Empty(t, shutdown)
time.Sleep(time.Second)
synctest.Wait()
synctest.Sleep(time.Second)
require.Len(t, shutdown, 1)
assert.NoError(t, <-shutdown)
})
Expand Down
Loading