Skip to content

Commit

Permalink
Fix test for parallel run.
Browse files Browse the repository at this point in the history
Specify different ports for package tests.
  • Loading branch information
kozlovic committed Jan 25, 2016
1 parent 3f6cf9f commit a4cf1de
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
11 changes: 8 additions & 3 deletions enc_test.go
@@ -1,6 +1,7 @@
package nats_test

import (
"fmt"
"testing"
"time"

Expand All @@ -9,8 +10,12 @@ import (
"github.com/nats-io/nats/encoders/protobuf/testdata"
)

// Since we import above nats packages, we need to have a different
// const name than TEST_PORT that we used on the other packages.
const ENC_TEST_PORT = 8268

var options = Options{
Url: "nats://localhost:22222",
Url: fmt.Sprintf("nats://localhost:%d", ENC_TEST_PORT),
AllowReconnect: true,
MaxReconnect: 10,
ReconnectWait: 100 * time.Millisecond,
Expand All @@ -22,7 +27,7 @@ var options = Options{
////////////////////////////////////////////////////////////////////////////////

func TestPublishErrorAfterSubscribeDecodeError(t *testing.T) {
ts := RunServerOnPort(22222)
ts := RunServerOnPort(ENC_TEST_PORT)
defer ts.Shutdown()
opts := options
nc, _ := opts.Connect()
Expand All @@ -48,7 +53,7 @@ func TestPublishErrorAfterSubscribeDecodeError(t *testing.T) {
}

func TestPublishErrorAfterInvalidPublishMessage(t *testing.T) {
ts := RunServerOnPort(22222)
ts := RunServerOnPort(ENC_TEST_PORT)
defer ts.Shutdown()
opts := options
nc, _ := opts.Connect()
Expand Down
13 changes: 8 additions & 5 deletions nats_test.go
Expand Up @@ -6,6 +6,7 @@ package nats

import (
"errors"
"fmt"
"reflect"
"testing"
"time"
Expand All @@ -32,8 +33,10 @@ func WaitTime(ch chan bool, timeout time.Duration) error {
// Reconnect tests
////////////////////////////////////////////////////////////////////////////////

const TEST_PORT = 8368

var reconnectOpts = Options{
Url: "nats://localhost:22222",
Url: fmt.Sprintf("nats://localhost:%d", TEST_PORT),
AllowReconnect: true,
MaxReconnect: 10,
ReconnectWait: 100 * time.Millisecond,
Expand All @@ -51,7 +54,7 @@ func RunServerWithOptions(opts server.Options) *server.Server {
}

func TestReconnectServerStats(t *testing.T) {
ts := RunServerOnPort(22222)
ts := RunServerOnPort(TEST_PORT)

opts := reconnectOpts
nc, _ := opts.Connect()
Expand All @@ -61,7 +64,7 @@ func TestReconnectServerStats(t *testing.T) {
ts.Shutdown()
// server is stopped here...

ts = RunServerOnPort(22222)
ts = RunServerOnPort(TEST_PORT)
defer ts.Shutdown()

if err := nc.FlushTimeout(5 * time.Second); err != nil {
Expand All @@ -79,7 +82,7 @@ func TestReconnectServerStats(t *testing.T) {
}

func TestParseStateReconnectFunctionality(t *testing.T) {
ts := RunServerOnPort(22222)
ts := RunServerOnPort(TEST_PORT)
ch := make(chan bool)

opts := reconnectOpts
Expand Down Expand Up @@ -131,7 +134,7 @@ func TestParseStateReconnectFunctionality(t *testing.T) {
t.Fatalf("Failed to publish message: %v\n", err)
}

ts = RunServerOnPort(22222)
ts = RunServerOnPort(TEST_PORT)
defer ts.Shutdown()

if err := ec.FlushTimeout(5 * time.Second); err != nil {
Expand Down

0 comments on commit a4cf1de

Please sign in to comment.