diff options
author | Wolfy-J <[email protected]> | 2018-06-07 12:29:01 +0300 |
---|---|---|
committer | Wolfy-J <[email protected]> | 2018-06-07 12:29:01 +0300 |
commit | 33040a9b1bce85e174ee68f6ba8c73b1dbf43b56 (patch) | |
tree | 6471d7c3c082d9bc0e46fac3a2de6c936fa00df3 /server_test.go | |
parent | d93294a8c37b81df06a1a46906815f70414ab01d (diff) |
test handle failed worker
Diffstat (limited to 'server_test.go')
-rw-r--r-- | server_test.go | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/server_test.go b/server_test.go index d309f0d0..8706f3ec 100644 --- a/server_test.go +++ b/server_test.go @@ -160,3 +160,34 @@ func TestServer_Reset(t *testing.T) { assert.Len(t, srv.Workers(), 1) assert.NotEqual(t, pid, srv.Workers()[0].Pid) } + +func TestServer_HandleWorkerFailure(t *testing.T) { + srv := NewServer( + func() *exec.Cmd { return exec.Command("php", "php-src/tests/client.php", "echo", "pipes") }, + &ServerConfig{ + Relay: "pipes", + Pool: Config{ + NumWorkers: 1, + AllocateTimeout: time.Second, + DestroyTimeout: time.Second, + }, + }) + defer srv.Stop() + + assert.NoError(t, srv.Start()) + + destructed := make(chan interface{}) + srv.Observe(func(e int, ctx interface{}) { + if e == EventWorkerCreate { + close(destructed) + } + }) + + // killing random worker and expecting pool to replace it + srv.Workers()[0].cmd.Process.Kill() + <-destructed + + for _, w := range srv.Workers() { + assert.Equal(t, StateReady, w.state.Value()) + } +} |