Skip to content

Commit

Permalink
improve test timeouts
Browse files Browse the repository at this point in the history
Summary: Unify and extend test timeouts so we don't fail randomly on slow runs.

Differential Revision: D56469346
  • Loading branch information
abulimov authored and facebook-github-bot committed Apr 23, 2024
1 parent e4f24e1 commit 15822c3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
6 changes: 3 additions & 3 deletions ptp/sptp/client/client_test.go
Expand Up @@ -123,7 +123,7 @@ func TestClientRun(t *testing.T) {
})

ctx := context.Background()
runResult := c.RunOnce(ctx, 100*time.Millisecond)
runResult := c.RunOnce(ctx, defaultTestTimeout)
require.NotNil(t, runResult)
require.NoError(t, runResult.Error, "full client run should succeed")
require.Equal(t, "127.0.0.1", runResult.Server, "run result should have correct server")
Expand Down Expand Up @@ -159,7 +159,7 @@ func TestClientTimeout(t *testing.T) {
eventConn.EXPECT().WriteToWithTS(gomock.Any(), gomock.Any())

ctx := context.Background()
runResult := c.RunOnce(ctx, 100*time.Millisecond)
runResult := c.RunOnce(ctx, defaultTestTimeout)
require.NotNil(t, runResult)
require.Error(t, runResult.Error, "full client run should fail")
}
Expand Down Expand Up @@ -197,7 +197,7 @@ func TestClientBadPacket(t *testing.T) {
})

ctx := context.Background()
runResult := c.RunOnce(ctx, 100*time.Millisecond)
runResult := c.RunOnce(ctx, defaultTestTimeout)
require.NotNil(t, runResult)
require.Error(t, runResult.Error, "full client run should fail")
require.Equal(t, "127.0.0.1", runResult.Server, "run result should have correct server")
Expand Down
10 changes: 6 additions & 4 deletions ptp/sptp/client/sptp_test.go
Expand Up @@ -38,6 +38,8 @@ func init() {
log.SetLevel(log.DebugLevel)
}

const defaultTestTimeout = time.Second

func TestProcessResultsNoResults(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()
Expand Down Expand Up @@ -409,7 +411,7 @@ func TestRunListenerNoAddr(t *testing.T) {
}
err := p.initClients()
require.NoError(t, err)
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Millisecond)
ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout)
defer cancel()
err = p.RunListener(ctx)
require.EqualError(t, err, "received packet on port 320 with nil source address")
Expand Down Expand Up @@ -442,7 +444,7 @@ func TestRunListenerError(t *testing.T) {
}
err := p.initClients()
require.NoError(t, err)
ctx, cancel := context.WithTimeout(context.Background(), 100*time.Millisecond)
ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout)
defer cancel()
err = p.RunListener(ctx)
require.EqualError(t, err, "some error")
Expand Down Expand Up @@ -512,15 +514,15 @@ func TestRunListenerGood(t *testing.T) {
}
err := p.initClients()
require.NoError(t, err)
ctx, cancel := context.WithTimeout(context.Background(), 100*time.Millisecond)
ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout)
defer cancel()
err = p.RunListener(ctx)
require.ErrorIs(t, err, context.DeadlineExceeded)
receivedEvent10 := 0
receivedGen10 := 0
receivedEvent11 := 0
receivedGen11 := 0
nctx, ncancel := context.WithTimeout(context.Background(), 100*time.Millisecond)
nctx, ncancel := context.WithTimeout(context.Background(), defaultTestTimeout)
defer ncancel()
LOOP:
for {
Expand Down

0 comments on commit 15822c3

Please sign in to comment.