Skip to content

Commit 0eb718d

Browse files
committed
Merge pull request #522 from jacqui/master
Split NSQ test into separate functions for writing to and reading from topics/channels
2 parents dd77dcd + be042c2 commit 0eb718d

File tree

1 file changed

+23
-10
lines changed

1 file changed

+23
-10
lines changed

tests/nsq_test.go

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ type NSQSuite struct{}
1313

1414
var nsqSuite = Suite(&NSQSuite{})
1515

16-
func (s *NSQSuite) TestToFromNSQ(c *C) {
16+
func (s *NSQSuite) TestToNSQ(c *C) {
1717
log.Println("testing toNSQ")
1818

1919
toB, toC := test_utils.NewBlock("testingToNSQ", "tonsq")
@@ -28,6 +28,9 @@ func (s *NSQSuite) TestToFromNSQ(c *C) {
2828
toC.QueryChan <- &blocks.QueryMsg{MsgChan: toQueryChan, Route: "rule"}
2929
})
3030

31+
outChan := make(chan *blocks.Msg)
32+
toC.AddChan <- &blocks.AddChanMsg{Route: "1", Channel: outChan}
33+
3134
time.AfterFunc(time.Duration(2)*time.Second, func() {
3235
nsqMsg := map[string]interface{}{"Foo": "Bar"}
3336
postData := &blocks.Msg{Msg: nsqMsg, Route: "in"}
@@ -38,6 +41,25 @@ func (s *NSQSuite) TestToFromNSQ(c *C) {
3841
toC.QuitChan <- true
3942
})
4043

44+
for {
45+
select {
46+
case messageI := <-toQueryChan:
47+
c.Assert(messageI, DeepEquals, ruleMsg)
48+
49+
case message := <-outChan:
50+
log.Println("printing message from outChan:", message)
51+
52+
case err := <-toC.ErrChan:
53+
if err != nil {
54+
c.Errorf(err.Error())
55+
} else {
56+
return
57+
}
58+
}
59+
}
60+
}
61+
62+
func (s *NSQSuite) TestFromNSQ(c *C) {
4163
log.Println("testing fromNSQ")
4264

4365
fromB, fromC := test_utils.NewBlock("testingfromNSQ", "fromnsq")
@@ -65,18 +87,9 @@ func (s *NSQSuite) TestToFromNSQ(c *C) {
6587
case messageI := <-fromQueryChan:
6688
c.Assert(messageI, DeepEquals, nsqSetup)
6789

68-
case messageI := <-toQueryChan:
69-
c.Assert(messageI, DeepEquals, ruleMsg)
70-
7190
case message := <-outChan:
7291
log.Println("printing message from outChan:", message)
7392

74-
case err := <-toC.ErrChan:
75-
if err != nil {
76-
c.Errorf(err.Error())
77-
} else {
78-
return
79-
}
8093
case err := <-fromC.ErrChan:
8194
if err != nil {
8295
c.Errorf(err.Error())

0 commit comments

Comments
 (0)