diff options
author | Valery Piashchynski <[email protected]> | 2021-04-20 12:09:39 +0300 |
---|---|---|
committer | Valery Piashchynski <[email protected]> | 2021-04-20 12:09:39 +0300 |
commit | 2faf7bc2cd883294306466282f313bc5a1dc79ef (patch) | |
tree | a1e94592452e7840a5ce7c615766330e0a23fdb7 /tests/plugins | |
parent | a3ced86a77b406bd8d127135636d33e12517d7f8 (diff) |
- Make http.Serve() async
Signed-off-by: Valery Piashchynski <[email protected]>
Diffstat (limited to 'tests/plugins')
-rw-r--r-- | tests/plugins/gzip/plugin_test.go | 1 | ||||
-rw-r--r-- | tests/plugins/http/http_plugin_test.go | 39 |
2 files changed, 37 insertions, 3 deletions
diff --git a/tests/plugins/gzip/plugin_test.go b/tests/plugins/gzip/plugin_test.go index 9a9c760b..844fd411 100644 --- a/tests/plugins/gzip/plugin_test.go +++ b/tests/plugins/gzip/plugin_test.go @@ -81,6 +81,7 @@ func TestGzipPlugin(t *testing.T) { } }() + time.Sleep(time.Second * 2) t.Run("GzipCheckHeader", headerCheck) stopCh <- struct{}{} diff --git a/tests/plugins/http/http_plugin_test.go b/tests/plugins/http/http_plugin_test.go index 73d6d102..4a491990 100644 --- a/tests/plugins/http/http_plugin_test.go +++ b/tests/plugins/http/http_plugin_test.go @@ -1227,10 +1227,43 @@ func TestHttpBrokenPipes(t *testing.T) { err = cont.Init() assert.NoError(t, err) - _, err = cont.Serve() - assert.Error(t, err) + ch, err := cont.Serve() + assert.NoError(t, err) + + sig := make(chan os.Signal, 1) + signal.Notify(sig, os.Interrupt, syscall.SIGINT, syscall.SIGTERM) + + wg := &sync.WaitGroup{} + wg.Add(1) + + stopCh := make(chan struct{}, 1) + + go func() { + defer wg.Done() + for { + select { + // should be error from the plugin + case e := <-ch: + assert.Error(t, e.Error) + return + case <-sig: + err = cont.Stop() + if err != nil { + assert.FailNow(t, "error", err.Error()) + } + return + case <-stopCh: + // timeout + err = cont.Stop() + if err != nil { + assert.FailNow(t, "error", err.Error()) + } + return + } + } + }() - assert.NoError(t, cont.Stop()) + wg.Wait() } func TestHTTPSupervisedPool(t *testing.T) { |