Skip to content

Commit

Permalink
Merge pull request #36 from rewardStyle/FixTryToSendTest
Browse files Browse the repository at this point in the history
Make TestProducerTryToSend more deterministic
  • Loading branch information
fjordan authored Nov 30, 2016
2 parents 855787f + ba053f1 commit 6898a3c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
6 changes: 3 additions & 3 deletions listener_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ package kinetic

import (
"errors"
. "github.com/smartystreets/goconvey/convey"
"runtime"
"sync"
"syscall"
"testing"
"time"

. "github.com/smartystreets/goconvey/convey"
)

const testEndpoint = "http://127.0.0.1:4567"
Expand All @@ -23,7 +23,7 @@ func TestListenerStop(t *testing.T) {

Convey("It should stop listening if sent an interrupt signal", func() {
listener.interrupts <- syscall.SIGINT

runtime.Gosched()
// Let it finish stopping
<-time.After(3 * time.Second)

Expand Down
6 changes: 4 additions & 2 deletions producer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ package kinetic
import (
"encoding/binary"
"errors"
. "github.com/smartystreets/goconvey/convey"
"runtime"
"syscall"
"testing"
"time"

. "github.com/smartystreets/goconvey/convey"
)

func TestProducerStop(t *testing.T) {
Expand All @@ -19,6 +19,7 @@ func TestProducerStop(t *testing.T) {

Convey("It should stop producing if sent an interrupt signal", func() {
producer.interrupts <- syscall.SIGINT
runtime.Gosched()

// Wait for it to stop
for {
Expand Down Expand Up @@ -83,6 +84,7 @@ func TestProducerTryToSend(t *testing.T) {
producer, _ := new(Producer).InitC("your-stream", "0", "LATEST", "accesskey", "secretkey", "us-east-1", 4)
producer.NewEndpoint(testEndpoint, "your-stream")
producer.Close() // This is to make the test deterministic. It stops producer from sending messages.
runtime.Gosched()
var totDropped int
for i := 0; i < 5000; i++ {
b := make([]byte, 2)
Expand Down

0 comments on commit 6898a3c

Please sign in to comment.