summaryrefslogtreecommitdiff
path: root/server_test.go
diff options
context:
space:
mode:
authorWolfy-J <[email protected]>2018-06-07 15:37:21 +0300
committerWolfy-J <[email protected]>2018-06-07 15:37:21 +0300
commitef26e854480562de15edffe3b38f86bc22bedd76 (patch)
tree258d89fb103ae184a87dcb47de42a8f275582866 /server_test.go
parent33040a9b1bce85e174ee68f6ba8c73b1dbf43b56 (diff)
server failure
Diffstat (limited to 'server_test.go')
-rw-r--r--server_test.go44
1 files changed, 37 insertions, 7 deletions
diff --git a/server_test.go b/server_test.go
index 8706f3ec..1cab7cd3 100644
--- a/server_test.go
+++ b/server_test.go
@@ -161,7 +161,7 @@ func TestServer_Reset(t *testing.T) {
assert.NotEqual(t, pid, srv.Workers()[0].Pid)
}
-func TestServer_HandleWorkerFailure(t *testing.T) {
+func TestServer_ReplacePool(t *testing.T) {
srv := NewServer(
func() *exec.Cmd { return exec.Command("php", "php-src/tests/client.php", "echo", "pipes") },
&ServerConfig{
@@ -176,18 +176,48 @@ func TestServer_HandleWorkerFailure(t *testing.T) {
assert.NoError(t, srv.Start())
- destructed := make(chan interface{})
+ constructed := make(chan interface{})
srv.Observe(func(e int, ctx interface{}) {
- if e == EventWorkerCreate {
- close(destructed)
+ if e == EventPoolConstruct {
+ close(constructed)
}
})
- // killing random worker and expecting pool to replace it
- srv.Workers()[0].cmd.Process.Kill()
- <-destructed
+ srv.Reset()
+ <-constructed
for _, w := range srv.Workers() {
assert.Equal(t, StateReady, w.state.Value())
}
}
+
+func TestServer_HandleServerFailure(t *testing.T) {
+ mode := "pipes"
+ srv := NewServer(
+ func() *exec.Cmd { return exec.Command("php", "php-src/tests/client.php", "echo", mode) },
+ &ServerConfig{
+ Relay: "pipes",
+ Pool: Config{
+ NumWorkers: 1,
+ AllocateTimeout: time.Second,
+ DestroyTimeout: time.Second,
+ },
+ })
+ defer srv.Stop()
+
+ assert.NoError(t, srv.Start())
+
+ failure := make(chan interface{})
+ srv.Observe(func(e int, ctx interface{}) {
+ if e == EventServerFailure {
+ close(failure)
+ }
+ })
+
+ // killing random worker and expecting pool to replace it
+ mode = "suddenly-broken"
+ srv.Workers()[0].cmd.Process.Kill()
+
+ <-failure
+ assert.True(t, true)
+}