File tree Expand file tree Collapse file tree 2 files changed +16
-0
lines changed Expand file tree Collapse file tree 2 files changed +16
-0
lines changed Original file line number Diff line number Diff line change @@ -87,6 +87,10 @@ type Server struct {
87
87
// defaultingOnce ensures that the default fields are only ever set once.
88
88
defaultingOnce sync.Once
89
89
90
+ // started is set to true immediately before the server is started
91
+ // and thus can be used to check if the server has been started
92
+ started bool
93
+
90
94
// mu protects access to the webhook map & setFields for Start, Register, etc
91
95
mu sync.Mutex
92
96
}
@@ -272,6 +276,9 @@ func (s *Server) Start(ctx context.Context) error {
272
276
close (idleConnsClosed )
273
277
}()
274
278
279
+ s .mu .Lock ()
280
+ s .started = true
281
+ s .mu .Unlock ()
275
282
if err := srv .Serve (listener ); err != nil && err != http .ErrServerClosed {
276
283
return err
277
284
}
@@ -280,6 +287,13 @@ func (s *Server) Start(ctx context.Context) error {
280
287
return nil
281
288
}
282
289
290
+ // Started returns if the server has been started
291
+ func (s * Server ) Started () bool {
292
+ s .mu .Lock ()
293
+ defer s .mu .Unlock ()
294
+ return s .started
295
+ }
296
+
283
297
// InjectFunc injects the field setter into the server.
284
298
func (s * Server ) InjectFunc (f inject.Func ) error {
285
299
s .setFields = f
Original file line number Diff line number Diff line change @@ -137,6 +137,8 @@ var _ = Describe("Webhook Server", func() {
137
137
return ioutil .ReadAll (resp .Body )
138
138
}).Should (Equal ([]byte ("gadzooks!" )))
139
139
140
+ Expect (server .Started ()).To (BeTrue ())
141
+
140
142
ctxCancel ()
141
143
Eventually (doneCh , "4s" ).Should (BeClosed ())
142
144
})
You can’t perform that action at this time.
0 commit comments