This commit is contained in:
Jeff Mitchell authored and GitHub committed 2024-09-18 11:09:15 -04:00
1 parent 913e6d755f
commit b120a03f43
4 files changed
+32 -3

No files matched your search

@@ -17,6 +17,7 @@ type options struct {
withRecheckSupportInterval time.Duration
testWithIntervalRandomizationFactor float64
testWithIntervalRandomizationFactorSet bool
WithReadyToServeNotificationCh chan struct{}
withBoundaryTokenReaderFunc cache.BoundaryTokenReaderFn
withUrl string
@@ -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
}
}
@@ -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)
})
}
@@ -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())
}