diff options
author | Aliaksandr Valialkin <valyala@gmail.com> | 2016-07-12 12:30:33 +0300 |
---|---|---|
committer | Aliaksandr Valialkin <valyala@gmail.com> | 2016-07-12 12:30:38 +0300 |
commit | 886e5411604884629c566961ea8ed2cec074e4b1 (patch) | |
tree | 600e63baf61ab16a76d4800089dbe6d79ff1d59c /workerpool_test.go | |
parent | Issue #131: document redirects' following for client functions (diff) | |
download | fasthttp-886e5411604884629c566961ea8ed2cec074e4b1.tar.gz fasthttp-886e5411604884629c566961ea8ed2cec074e4b1.tar.bz2 fasthttp-886e5411604884629c566961ea8ed2cec074e4b1.zip |
Removed 'recover-from-panic' band-aids.
All the panics must be handled by the user code.
Diffstat (limited to 'workerpool_test.go')
-rw-r--r-- | workerpool_test.go | 99 |
1 files changed, 0 insertions, 99 deletions
diff --git a/workerpool_test.go b/workerpool_test.go index eceb187..6f63f2c 100644 --- a/workerpool_test.go +++ b/workerpool_test.go @@ -1,10 +1,8 @@ package fasthttp import ( - "fmt" "io/ioutil" "net" - "sync/atomic" "testing" "time" @@ -168,100 +166,3 @@ func testWorkerPoolMaxWorkersCount(t *testing.T) { } wp.Stop() } - -func TestWorkerPoolPanicErrorSerial(t *testing.T) { - testWorkerPoolPanicErrorMulti(t) -} - -func TestWorkerPoolPanicErrorConcurrent(t *testing.T) { - concurrency := 10 - ch := make(chan struct{}, concurrency) - for i := 0; i < concurrency; i++ { - go func() { - testWorkerPoolPanicErrorMulti(t) - ch <- struct{}{} - }() - } - for i := 0; i < concurrency; i++ { - select { - case <-ch: - case <-time.After(time.Second): - t.Fatalf("timeout") - } - } -} - -func testWorkerPoolPanicErrorMulti(t *testing.T) { - var globalCount uint64 - wp := &workerPool{ - WorkerFunc: func(conn net.Conn) error { - count := atomic.AddUint64(&globalCount, 1) - switch count % 3 { - case 0: - panic("foobar") - case 1: - return fmt.Errorf("fake error") - } - return nil - }, - MaxWorkersCount: 1000, - MaxIdleWorkerDuration: time.Millisecond, - Logger: &customLogger{}, - } - - for i := 0; i < 10; i++ { - testWorkerPoolPanicError(t, wp) - } -} - -func testWorkerPoolPanicError(t *testing.T, wp *workerPool) { - wp.Start() - - ln := fasthttputil.NewInmemoryListener() - - clientsCount := 10 - clientCh := make(chan struct{}, clientsCount) - for i := 0; i < clientsCount; i++ { - go func() { - conn, err := ln.Dial() - if err != nil { - t.Fatalf("unexpected error: %s", err) - } - data, err := ioutil.ReadAll(conn) - if err != nil { - t.Fatalf("unexpected error: %s", err) - } - if len(data) > 0 { - t.Fatalf("unexpected data read: %q. Expecting empty data", data) - } - if err = conn.Close(); err != nil { - t.Fatalf("unexpected error: %s", err) - } - clientCh <- struct{}{} - }() - } - - for i := 0; i < clientsCount; i++ { - conn, err := ln.Accept() - if err != nil { - t.Fatalf("unexpected error: %s", err) - } - if !wp.Serve(conn) { - t.Fatalf("worker pool mustn't be full") - } - } - - for i := 0; i < clientsCount; i++ { - select { - case <-clientCh: - case <-time.After(time.Second): - t.Fatalf("timeout") - } - } - - if err := ln.Close(); err != nil { - t.Fatalf("unexpected error: %s", err) - } - - wp.Stop() -} |