@@ -24,12 +24,13 @@ const (
2424 RequestTimeout = 5 * time .Second
2525)
2626
27- func getMetadata (n * NSQD ) (* meta , error ) {
27+ func getMetadata (t * testing. T , n * NSQD ) (* meta , error ) {
2828 fn := newMetadataFile (n .getOpts ())
2929 data , err := ioutil .ReadFile (fn )
3030 if err != nil {
3131 return nil , err
3232 }
33+ t .Logf ("reading metadata from: %s, %s" , fn , data )
3334
3435 var m meta
3536 err = json .Unmarshal (data , & m )
@@ -66,7 +67,7 @@ func TestStartup(t *testing.T) {
6667 test .Nil (t , err )
6768 atomic .StoreInt32 (& nsqd .isLoading , 1 )
6869 nsqd .GetTopic (topicName ) // will not persist if `flagLoading`
69- m , err := getMetadata (nsqd )
70+ m , err := getMetadata (t , nsqd )
7071 test .Nil (t , err )
7172 test .Equal (t , 0 , len (m .Topics ))
7273 nsqd .DeleteExistingTopic (topicName )
@@ -90,14 +91,22 @@ func TestStartup(t *testing.T) {
9091 test .Equal (t , body , msg .Body )
9192 }
9293
93- // make sure metadata shows the topic
94- m , err = getMetadata (nsqd )
95- test .Nil (t , err )
96- test .Equal (t , 1 , len (m .Topics ))
97- test .Equal (t , topicName , m .Topics [0 ].Name )
98- test .Equal (t , 1 , len (m .Topics [0 ].Channels ))
99- test .Equal (t , "ch1" , m .Topics [0 ].Channels [0 ].Name )
94+ // make sure metadata shows the topic/channel
95+ for i := 0 ; i < 10 ; i ++ {
96+ m , err = getMetadata (t , nsqd )
97+ test .Nil (t , err )
98+ if len (m .Topics ) != 1 ||
99+ m .Topics [0 ].Name != topicName ||
100+ len (m .Topics [0 ].Channels ) != 1 ||
101+ m .Topics [0 ].Channels [0 ].Name != "ch1" {
102+ time .Sleep (10 * time .Millisecond )
103+ continue
104+ }
105+ goto success
106+ }
107+ panic ("should not happen" )
100108
109+ success:
101110 exitChan <- 1
102111 <- doneExitChan
103112
@@ -308,7 +317,7 @@ func TestPauseMetadata(t *testing.T) {
308317 nsqd .PersistMetadata ()
309318
310319 var isPaused = func (n * NSQD , topicIndex int , channelIndex int ) bool {
311- m , _ := getMetadata (n )
320+ m , _ := getMetadata (t , n )
312321 return m .Topics [topicIndex ].Channels [channelIndex ].Paused
313322 }
314323
0 commit comments