diff options
author | Wolfy-J <[email protected]> | 2019-05-03 12:47:22 +0300 |
---|---|---|
committer | Wolfy-J <[email protected]> | 2019-05-03 12:47:22 +0300 |
commit | aa2754aed64bd0b54b1e2c4090a28a2e6b566361 (patch) | |
tree | be4508a93c7bd8b7586335567bd4394683ee0f49 /server_test.go | |
parent | b5decb711e550242bd0e057f8867b7ec85e423b7 (diff) |
more tests, watcher tests
Diffstat (limited to 'server_test.go')
-rw-r--r-- | server_test.go | 88 |
1 files changed, 44 insertions, 44 deletions
diff --git a/server_test.go b/server_test.go index 4646ebc9..b86a5a66 100644 --- a/server_test.go +++ b/server_test.go @@ -9,7 +9,7 @@ import ( ) func TestServer_PipesEcho(t *testing.T) { - srv := NewServer( + rr := NewServer( &ServerConfig{ Command: "php tests/client.php echo pipes", Relay: "pipes", @@ -19,11 +19,11 @@ func TestServer_PipesEcho(t *testing.T) { DestroyTimeout: time.Second, }, }) - defer srv.Stop() + defer rr.Stop() - assert.NoError(t, srv.Start()) + assert.NoError(t, rr.Start()) - res, err := srv.Exec(&Payload{Body: []byte("hello")}) + res, err := rr.Exec(&Payload{Body: []byte("hello")}) assert.NoError(t, err) assert.NotNil(t, res) @@ -34,7 +34,7 @@ func TestServer_PipesEcho(t *testing.T) { } func TestServer_SocketEcho(t *testing.T) { - srv := NewServer( + rr := NewServer( &ServerConfig{ Command: "php tests/client.php echo tcp", Relay: "tcp://:9007", @@ -45,11 +45,11 @@ func TestServer_SocketEcho(t *testing.T) { DestroyTimeout: time.Second, }, }) - defer srv.Stop() + defer rr.Stop() - assert.NoError(t, srv.Start()) + assert.NoError(t, rr.Start()) - res, err := srv.Exec(&Payload{Body: []byte("hello")}) + res, err := rr.Exec(&Payload{Body: []byte("hello")}) assert.NoError(t, err) assert.NotNil(t, res) @@ -60,7 +60,7 @@ func TestServer_SocketEcho(t *testing.T) { } func TestServer_Configure_BeforeStart(t *testing.T) { - srv := NewServer( + rr := NewServer( &ServerConfig{ Command: "php tests/client.php echo pipes", Relay: "pipes", @@ -70,9 +70,9 @@ func TestServer_Configure_BeforeStart(t *testing.T) { DestroyTimeout: time.Second, }, }) - defer srv.Stop() + defer rr.Stop() - err := srv.Reconfigure(&ServerConfig{ + err := rr.Reconfigure(&ServerConfig{ Command: "php tests/client.php echo pipes", Relay: "pipes", Pool: &Config{ @@ -83,9 +83,9 @@ func TestServer_Configure_BeforeStart(t *testing.T) { }) assert.NoError(t, err) - assert.NoError(t, srv.Start()) + assert.NoError(t, rr.Start()) - res, err := srv.Exec(&Payload{Body: []byte("hello")}) + res, err := rr.Exec(&Payload{Body: []byte("hello")}) assert.NoError(t, err) assert.NotNil(t, res) @@ -93,11 +93,11 @@ func TestServer_Configure_BeforeStart(t *testing.T) { assert.Nil(t, res.Context) assert.Equal(t, "hello", res.String()) - assert.Len(t, srv.Workers(), 2) + assert.Len(t, rr.Workers(), 2) } func TestServer_Stop_NotStarted(t *testing.T) { - srv := NewServer( + rr := NewServer( &ServerConfig{ Command: "php tests/client.php echo pipes", Relay: "pipes", @@ -108,12 +108,12 @@ func TestServer_Stop_NotStarted(t *testing.T) { }, }) - srv.Stop() - assert.Nil(t, srv.Workers()) + rr.Stop() + assert.Nil(t, rr.Workers()) } func TestServer_Reconfigure(t *testing.T) { - srv := NewServer( + rr := NewServer( &ServerConfig{ Command: "php tests/client.php echo pipes", Relay: "pipes", @@ -123,12 +123,12 @@ func TestServer_Reconfigure(t *testing.T) { DestroyTimeout: time.Second, }, }) - defer srv.Stop() + defer rr.Stop() - assert.NoError(t, srv.Start()) - assert.Len(t, srv.Workers(), 1) + assert.NoError(t, rr.Start()) + assert.Len(t, rr.Workers(), 1) - err := srv.Reconfigure(&ServerConfig{ + err := rr.Reconfigure(&ServerConfig{ Command: "php tests/client.php echo pipes", Relay: "pipes", Pool: &Config{ @@ -139,11 +139,11 @@ func TestServer_Reconfigure(t *testing.T) { }) assert.NoError(t, err) - assert.Len(t, srv.Workers(), 2) + assert.Len(t, rr.Workers(), 2) } func TestServer_Reset(t *testing.T) { - srv := NewServer( + rr := NewServer( &ServerConfig{ Command: "php tests/client.php echo pipes", Relay: "pipes", @@ -153,19 +153,19 @@ func TestServer_Reset(t *testing.T) { DestroyTimeout: time.Second, }, }) - defer srv.Stop() + defer rr.Stop() - assert.NoError(t, srv.Start()) - assert.Len(t, srv.Workers(), 1) + assert.NoError(t, rr.Start()) + assert.Len(t, rr.Workers(), 1) - pid := *srv.Workers()[0].Pid - assert.NoError(t, srv.Reset()) - assert.Len(t, srv.Workers(), 1) - assert.NotEqual(t, pid, srv.Workers()[0].Pid) + pid := *rr.Workers()[0].Pid + assert.NoError(t, rr.Reset()) + assert.Len(t, rr.Workers(), 1) + assert.NotEqual(t, pid, rr.Workers()[0].Pid) } func TestServer_ReplacePool(t *testing.T) { - srv := NewServer( + rr := NewServer( &ServerConfig{ Command: "php tests/client.php echo pipes", Relay: "pipes", @@ -175,27 +175,27 @@ func TestServer_ReplacePool(t *testing.T) { DestroyTimeout: time.Second, }, }) - defer srv.Stop() + defer rr.Stop() - assert.NoError(t, srv.Start()) + assert.NoError(t, rr.Start()) constructed := make(chan interface{}) - srv.Listen(func(e int, ctx interface{}) { + rr.Listen(func(e int, ctx interface{}) { if e == EventPoolConstruct { close(constructed) } }) - srv.Reset() + rr.Reset() <-constructed - for _, w := range srv.Workers() { + for _, w := range rr.Workers() { assert.Equal(t, StateReady, w.state.Value()) } } func TestServer_ServerFailure(t *testing.T) { - srv := NewServer(&ServerConfig{ + rr := NewServer(&ServerConfig{ Command: "php tests/client.php echo pipes", Relay: "pipes", Pool: &Config{ @@ -204,25 +204,25 @@ func TestServer_ServerFailure(t *testing.T) { DestroyTimeout: time.Second, }, }) - defer srv.Stop() + defer rr.Stop() - assert.NoError(t, srv.Start()) + assert.NoError(t, rr.Start()) failure := make(chan interface{}) - srv.Listen(func(e int, ctx interface{}) { + rr.Listen(func(e int, ctx interface{}) { if e == EventServerFailure { failure <- nil } }) // emulating potential server failure - srv.cfg.Command = "php tests/client.php echo broken-connection" - srv.pool.(*StaticPool).cmd = func() *exec.Cmd { + rr.cfg.Command = "php tests/client.php echo broken-connection" + rr.pool.(*StaticPool).cmd = func() *exec.Cmd { return exec.Command("php", "tests/client.php", "echo", "broken-connection") } // killing random worker and expecting pool to replace it - srv.Workers()[0].cmd.Process.Kill() + rr.Workers()[0].cmd.Process.Kill() <-failure assert.True(t, true) |