forked from nsqio/nsq
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
nsqd: refactor stats collection for regression introduced in nsqio#242
- Loading branch information
1 parent
1154c59
commit f25f1bb
Showing
2 changed files
with
52 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/bitly/nsq/nsq" | ||
"github.com/bmizerany/assert" | ||
"io/ioutil" | ||
"log" | ||
"os" | ||
"strconv" | ||
"testing" | ||
"time" | ||
) | ||
|
||
func TestStats(t *testing.T) { | ||
log.SetOutput(ioutil.Discard) | ||
defer log.SetOutput(os.Stdout) | ||
|
||
options := NewNsqdOptions() | ||
tcpAddr, _, nsqd := mustStartNSQd(options) | ||
defer nsqd.Exit() | ||
|
||
topicName := "test_stats" + strconv.Itoa(int(time.Now().Unix())) | ||
topic := nsqd.GetTopic(topicName) | ||
msg := nsq.NewMessage(<-nsqd.idChan, []byte("test body")) | ||
topic.PutMessage(msg) | ||
|
||
conn, err := mustConnectNSQd(tcpAddr) | ||
assert.Equal(t, err, nil) | ||
|
||
identify(t, conn) | ||
sub(t, conn, topicName, "ch") | ||
|
||
stats := nsqd.getStats() | ||
assert.Equal(t, len(stats), 1) | ||
assert.Equal(t, len(stats[0].Channels), 1) | ||
assert.Equal(t, len(stats[0].Channels[0].Clients), 1) | ||
log.Printf("stats: %+v", stats) | ||
} |