Skip to content
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

Fix tests #5114

Merged
merged 1 commit into from
Sep 18, 2024
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
10 changes: 7 additions & 3 deletions internal/clientcache/cmd/search/search_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,19 @@
return nil, errors.New("test not found error")
}

readyNotificationCh := make(chan struct{})
srv := daemon.NewTestServer(t, cmd)
var wg sync.WaitGroup
wg.Add(1)
go func() {
defer wg.Done()
srv.Serve(t, daemon.WithBoundaryTokenReaderFunc(ctx, boundaryTokenReaderFn))
srv.Serve(

Check failure on line 70 in internal/clientcache/cmd/search/search_test.go

View workflow job for this annotation

GitHub Actions / Run Linter

Error return value of `srv.Serve` is not checked (errcheck)
t,
daemon.WithBoundaryTokenReaderFunc(ctx, boundaryTokenReaderFn),
daemon.WithReadyToServeNotificationCh(context.Background(), readyNotificationCh),
)
}()
// Give the store some time to get initialized
time.Sleep(100 * time.Millisecond)
<-readyNotificationCh
srv.AddKeyringToken(t, "address", "keyringtype", "tokenname", at.Id, boundaryTokenReaderFn)
srv.AddKeyringToken(t, "address", "keyringtype", "unsupported", unsupportedAt.Id, boundaryTokenReaderFn)

Expand Down
12 changes: 12 additions & 0 deletions internal/clientcache/internal/daemon/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ type options struct {
withRecheckSupportInterval time.Duration
testWithIntervalRandomizationFactor float64
testWithIntervalRandomizationFactorSet bool
WithReadyToServeNotificationCh chan struct{}
withBoundaryTokenReaderFunc cache.BoundaryTokenReaderFn

withUrl string
Expand Down Expand Up @@ -99,3 +100,14 @@ func WithBoundaryTokenReaderFunc(_ context.Context, fn cache.BoundaryTokenReader
return nil
}
}

// WithReadyToServeNotificationCh provides an optional channel to notify when
// the server is ready to serve; mainly used for test timing but exported for
// availability. The channel will be closed just before the HTTP server is
// started.
func WithReadyToServeNotificationCh(_ context.Context, readyCh chan struct{}) Option {
return func(o *options) error {
o.WithReadyToServeNotificationCh = readyCh
return nil
}
}
10 changes: 10 additions & 0 deletions internal/clientcache/internal/daemon/options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,14 @@ func Test_GetOpts(t *testing.T) {
testOpts := getDefaultOptions()
assert.Equal(t, opts, testOpts)
})
t.Run("WithReadyToServeNotificationCh", func(t *testing.T) {
ch := make(chan struct{})
opts, err := getOpts(WithReadyToServeNotificationCh(ctx, ch))
require.NoError(t, err)
assert.NotNil(t, opts.WithReadyToServeNotificationCh)
testOpts := getDefaultOptions()
assert.Nil(t, testOpts.WithReadyToServeNotificationCh)
testOpts.WithReadyToServeNotificationCh = ch
assert.Equal(t, opts, testOpts)
})
}
3 changes: 3 additions & 0 deletions internal/clientcache/internal/daemon/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,9 @@ func (s *CacheServer) Serve(ctx context.Context, cmd Commander, opt ...Option) e
return ctx
},
}
if opts.WithReadyToServeNotificationCh != nil {
close(opts.WithReadyToServeNotificationCh)
}
if err = s.httpSrv.Serve(l); err != nil && err != http.ErrServerClosed && !errors.Is(err, net.ErrClosed) {
event.WriteSysEvent(ctx, op, "error closing server", "err", err.Error())
}
Expand Down
Loading