diff options
Diffstat (limited to 'socket_factory_test.go')
-rw-r--r-- | socket_factory_test.go | 75 |
1 files changed, 50 insertions, 25 deletions
diff --git a/socket_factory_test.go b/socket_factory_test.go index d0d643af..214a4851 100644 --- a/socket_factory_test.go +++ b/socket_factory_test.go @@ -19,7 +19,7 @@ func Test_Tcp_Start(t *testing.T) { t.Skip("socket is busy") } - cmd := exec.Command("php", "tests/client.php", "echo", "tcp") + cmd := exec.Command("php", "php-src/tests/client.php", "echo", "tcp") w, err := NewSocketFactory(ls, time.Minute).SpawnWorker(cmd) assert.NoError(t, err) @@ -32,6 +32,31 @@ func Test_Tcp_Start(t *testing.T) { w.Stop() } +func Test_Tcp_StartCloseFactory(t *testing.T) { + time.Sleep(time.Millisecond * 10) // to ensure free socket + + ls, err := net.Listen("tcp", "localhost:9007") + if assert.NoError(t, err) { + } else { + t.Skip("socket is busy") + } + + cmd := exec.Command("php", "php-src/tests/client.php", "echo", "tcp") + + f := NewSocketFactory(ls, time.Minute) + defer f.Close() + + w, err := f.SpawnWorker(cmd) + assert.NoError(t, err) + assert.NotNil(t, w) + + go func() { + assert.NoError(t, w.Wait()) + }() + + w.Stop() +} + func Test_Tcp_StartError(t *testing.T) { time.Sleep(time.Millisecond * 10) // to ensure free socket @@ -42,7 +67,7 @@ func Test_Tcp_StartError(t *testing.T) { t.Skip("socket is busy") } - cmd := exec.Command("php", "tests/client.php", "echo", "pipes") + cmd := exec.Command("php", "php-src/tests/client.php", "echo", "pipes") cmd.Start() w, err := NewSocketFactory(ls, time.Minute).SpawnWorker(cmd) @@ -60,7 +85,7 @@ func Test_Tcp_Failboot(t *testing.T) { t.Skip("socket is busy") } - cmd := exec.Command("php", "tests/failboot.php") + cmd := exec.Command("php", "php-src/tests/failboot.php") w, err := NewSocketFactory(ls, time.Minute).SpawnWorker(cmd) assert.Nil(t, w) @@ -78,7 +103,7 @@ func Test_Tcp_Timeout(t *testing.T) { t.Skip("socket is busy") } - cmd := exec.Command("php", "tests/slow-client.php", "echo", "tcp", "200", "0") + cmd := exec.Command("php", "php-src/tests/slow-client.php", "echo", "tcp", "200", "0") w, err := NewSocketFactory(ls, time.Millisecond*100).SpawnWorker(cmd) assert.Nil(t, w) @@ -96,7 +121,7 @@ func Test_Tcp_Invalid(t *testing.T) { t.Skip("socket is busy") } - cmd := exec.Command("php", "tests/invalid.php") + cmd := exec.Command("php", "php-src/tests/invalid.php") w, err := NewSocketFactory(ls, time.Minute).SpawnWorker(cmd) assert.Error(t, err) @@ -113,7 +138,7 @@ func Test_Tcp_Broken(t *testing.T) { t.Skip("socket is busy") } - cmd := exec.Command("php", "tests/client.php", "broken", "tcp") + cmd := exec.Command("php", "php-src/tests/client.php", "broken", "tcp") w, err := NewSocketFactory(ls, time.Minute).SpawnWorker(cmd) go func() { @@ -140,7 +165,7 @@ func Test_Tcp_Echo(t *testing.T) { t.Skip("socket is busy") } - cmd := exec.Command("php", "tests/client.php", "echo", "tcp") + cmd := exec.Command("php", "php-src/tests/client.php", "echo", "tcp") w, err := NewSocketFactory(ls, time.Minute).SpawnWorker(cmd) go func() { @@ -159,7 +184,7 @@ func Test_Tcp_Echo(t *testing.T) { } func Test_Unix_Start(t *testing.T) { - if runtime.GOOS == "windows" || runtime.GOOS == "darwin" { + if runtime.GOOS == "windows" { t.Skip("not supported on " + runtime.GOOS) } @@ -170,7 +195,7 @@ func Test_Unix_Start(t *testing.T) { t.Skip("socket is busy") } - cmd := exec.Command("php", "tests/client.php", "echo", "unix") + cmd := exec.Command("php", "php-src/tests/client.php", "echo", "unix") w, err := NewSocketFactory(ls, time.Minute).SpawnWorker(cmd) assert.NoError(t, err) @@ -184,7 +209,7 @@ func Test_Unix_Start(t *testing.T) { } func Test_Unix_Failboot(t *testing.T) { - if runtime.GOOS == "windows" || runtime.GOOS == "darwin" { + if runtime.GOOS == "windows" { t.Skip("not supported on " + runtime.GOOS) } @@ -195,7 +220,7 @@ func Test_Unix_Failboot(t *testing.T) { t.Skip("socket is busy") } - cmd := exec.Command("php", "tests/failboot.php") + cmd := exec.Command("php", "php-src/tests/failboot.php") w, err := NewSocketFactory(ls, time.Minute).SpawnWorker(cmd) assert.Nil(t, w) @@ -204,7 +229,7 @@ func Test_Unix_Failboot(t *testing.T) { } func Test_Unix_Timeout(t *testing.T) { - if runtime.GOOS == "windows" || runtime.GOOS == "darwin" { + if runtime.GOOS == "windows" { t.Skip("not supported on " + runtime.GOOS) } @@ -215,7 +240,7 @@ func Test_Unix_Timeout(t *testing.T) { t.Skip("socket is busy") } - cmd := exec.Command("php", "tests/slow-client.php", "echo", "unix", "200", "0") + cmd := exec.Command("php", "php-src/tests/slow-client.php", "echo", "unix", "200", "0") w, err := NewSocketFactory(ls, time.Millisecond*100).SpawnWorker(cmd) assert.Nil(t, w) @@ -224,7 +249,7 @@ func Test_Unix_Timeout(t *testing.T) { } func Test_Unix_Invalid(t *testing.T) { - if runtime.GOOS == "windows" || runtime.GOOS == "darwin" { + if runtime.GOOS == "windows" { t.Skip("not supported on " + runtime.GOOS) } @@ -235,7 +260,7 @@ func Test_Unix_Invalid(t *testing.T) { t.Skip("socket is busy") } - cmd := exec.Command("php", "tests/invalid.php") + cmd := exec.Command("php", "php-src/tests/invalid.php") w, err := NewSocketFactory(ls, time.Minute).SpawnWorker(cmd) assert.Error(t, err) @@ -243,7 +268,7 @@ func Test_Unix_Invalid(t *testing.T) { } func Test_Unix_Broken(t *testing.T) { - if runtime.GOOS == "windows" || runtime.GOOS == "darwin" { + if runtime.GOOS == "windows" { t.Skip("not supported on " + runtime.GOOS) } @@ -254,7 +279,7 @@ func Test_Unix_Broken(t *testing.T) { t.Skip("socket is busy") } - cmd := exec.Command("php", "tests/client.php", "broken", "unix") + cmd := exec.Command("php", "php-src/tests/client.php", "broken", "unix") w, err := NewSocketFactory(ls, time.Minute).SpawnWorker(cmd) go func() { @@ -272,7 +297,7 @@ func Test_Unix_Broken(t *testing.T) { } func Test_Unix_Echo(t *testing.T) { - if runtime.GOOS == "windows" || runtime.GOOS == "darwin" { + if runtime.GOOS == "windows" { t.Skip("not supported on " + runtime.GOOS) } @@ -283,7 +308,7 @@ func Test_Unix_Echo(t *testing.T) { t.Skip("socket is busy") } - cmd := exec.Command("php", "tests/client.php", "echo", "unix") + cmd := exec.Command("php", "php-src/tests/client.php", "echo", "unix") w, err := NewSocketFactory(ls, time.Minute).SpawnWorker(cmd) go func() { @@ -311,7 +336,7 @@ func Benchmark_Tcp_SpawnWorker_Stop(b *testing.B) { f := NewSocketFactory(ls, time.Minute) for n := 0; n < b.N; n++ { - cmd := exec.Command("php", "tests/client.php", "echo", "tcp") + cmd := exec.Command("php", "php-src/tests/client.php", "echo", "tcp") w, _ := f.SpawnWorker(cmd) go func() { @@ -332,7 +357,7 @@ func Benchmark_Tcp_Worker_ExecEcho(b *testing.B) { b.Skip("socket is busy") } - cmd := exec.Command("php", "tests/client.php", "echo", "tcp") + cmd := exec.Command("php", "php-src/tests/client.php", "echo", "tcp") w, _ := NewSocketFactory(ls, time.Minute).SpawnWorker(cmd) go func() { @@ -348,7 +373,7 @@ func Benchmark_Tcp_Worker_ExecEcho(b *testing.B) { } func Benchmark_Unix_SpawnWorker_Stop(b *testing.B) { - if runtime.GOOS == "windows" || runtime.GOOS == "darwin" { + if runtime.GOOS == "windows" { b.Skip("not supported on " + runtime.GOOS) } @@ -361,7 +386,7 @@ func Benchmark_Unix_SpawnWorker_Stop(b *testing.B) { f := NewSocketFactory(ls, time.Minute) for n := 0; n < b.N; n++ { - cmd := exec.Command("php", "tests/client.php", "echo", "unix") + cmd := exec.Command("php", "php-src/tests/client.php", "echo", "unix") w, _ := f.SpawnWorker(cmd) go func() { @@ -375,7 +400,7 @@ func Benchmark_Unix_SpawnWorker_Stop(b *testing.B) { } func Benchmark_Unix_Worker_ExecEcho(b *testing.B) { - if runtime.GOOS == "windows" || runtime.GOOS == "darwin" { + if runtime.GOOS == "windows" { b.Skip("not supported on " + runtime.GOOS) } @@ -386,7 +411,7 @@ func Benchmark_Unix_Worker_ExecEcho(b *testing.B) { b.Skip("socket is busy") } - cmd := exec.Command("php", "tests/client.php", "echo", "unix") + cmd := exec.Command("php", "php-src/tests/client.php", "echo", "unix") w, _ := NewSocketFactory(ls, time.Minute).SpawnWorker(cmd) go func() { |