Skip to content

Commit

Permalink
Fix race condition on test
Browse files Browse the repository at this point in the history
  • Loading branch information
devdinu committed Dec 30, 2019
1 parent 7db0735 commit 89902a0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
7 changes: 4 additions & 3 deletions consumer/consumer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package consumer
import (
"context"
"sync"
"sync/atomic"
"testing"
"time"

Expand Down Expand Up @@ -42,9 +43,9 @@ func (s *ConsumerSuite) SetupTest() {
func (s *ConsumerSuite) TestIfCallbackCalled() {
t := s.T()
ch := make(chan struct{}, 1)
var callbackCalled bool
var callbackCalled int32
call := func(msg *kafka.Message) {
callbackCalled = true
atomic.AddInt32(&callbackCalled, int32(1))
ch <- struct{}{}
}
ctx, cancel := context.WithTimeout(context.Background(), 5000*time.Millisecond)
Expand All @@ -55,7 +56,7 @@ func (s *ConsumerSuite) TestIfCallbackCalled() {
cancel()
s.consumer.Close()

assert.True(t, callbackCalled, "Callback called! Message received")
assert.GreaterOrEqual(t, callbackCalled, int32(1), "Callback called! Message received")
}

func TestConsumer(t *testing.T) {
Expand Down
2 changes: 2 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,5 +130,7 @@ helm install gojektech-incubator/kafqa --name kafqa-producer-001 --values=kafqa-
* Follow go [guidelines](https://golang.org/doc/effective_go.html) for development
* Ensure `make` succeeds

Thanks for all the [Contributors](https://github.com/gojekfarm/kafqa/graphs/contributors).

## License
Licensed under the [Apache License](./LICENSE), Version 2.0

0 comments on commit 89902a0

Please sign in to comment.