Skip to content
This repository has been archived by the owner on Mar 9, 2022. It is now read-only.

Commit

Permalink
listener: Avoid unnecessary use of TestMain
Browse files Browse the repository at this point in the history
TestMain isn't really necessary and it's best to isolate the gnatsd
instance for each test for reliability reasons.
  • Loading branch information
mjs committed May 22, 2018
1 parent 870e084 commit 6c0f8f3
Showing 1 changed file with 18 additions and 11 deletions.
29 changes: 18 additions & 11 deletions listener/listener_medium_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"fmt"
"net"
"net/http"
"os"
"strings"
"testing"
"time"
Expand Down Expand Up @@ -61,16 +60,6 @@ func init() {
statsInterval = 500 * time.Millisecond
}

func TestMain(m *testing.M) {
os.Exit(runMain(m))
}

func runMain(m *testing.M) int {
s := spouttest.RunGnatsd(natsPort)
defer s.Shutdown()
return m.Run()
}

func testConfig() *config.Config {
return &config.Config{
Mode: "listener",
Expand All @@ -87,6 +76,9 @@ func testConfig() *config.Config {
}

func TestBatching(t *testing.T) {
s := spouttest.RunGnatsd(natsPort)
defer s.Shutdown()

conf := testConfig()
conf.BatchMessages = numLines // batch messages into one packet

Expand Down Expand Up @@ -115,6 +107,9 @@ func TestBatching(t *testing.T) {
}

func TestWhatComesAroundGoesAround(t *testing.T) {
s := spouttest.RunGnatsd(natsPort)
defer s.Shutdown()

listener := startListener(t, testConfig())
defer listener.Stop()

Expand All @@ -141,6 +136,9 @@ func TestWhatComesAroundGoesAround(t *testing.T) {
}

func TestBatchBufferFull(t *testing.T) {
s := spouttest.RunGnatsd(natsPort)
defer s.Shutdown()

conf := testConfig()
// Set batch size high so that the batch will only send due to the
// batch buffer filling up.
Expand Down Expand Up @@ -183,6 +181,9 @@ loop:
}

func TestHTTPListener(t *testing.T) {
s := spouttest.RunGnatsd(natsPort)
defer s.Shutdown()

conf := testConfig()
listener, err := StartHTTPListener(conf)
require.NoError(t, err)
Expand Down Expand Up @@ -211,6 +212,9 @@ func TestHTTPListener(t *testing.T) {
}

func TestHTTPListenerBigPOST(t *testing.T) {
s := spouttest.RunGnatsd(natsPort)
defer s.Shutdown()

conf := testConfig()
conf.ListenerBatchBytes = 1024
// Use a batch size > 1. Even though a single write will be made,
Expand Down Expand Up @@ -244,6 +248,9 @@ func TestHTTPListenerBigPOST(t *testing.T) {
}

func TestHTTPListenerConcurrency(t *testing.T) {
s := spouttest.RunGnatsd(natsPort)
defer s.Shutdown()

conf := testConfig()
listener, err := StartHTTPListener(conf)
require.NoError(t, err)
Expand Down

0 comments on commit 6c0f8f3

Please sign in to comment.