@@ -20,74 +20,70 @@ package topic
2020import (
2121 "encoding/json"
2222 "testing"
23- "time"
2423
24+ "github.com/onsi/gomega"
2525 "github.com/streamnative/pulsarctl/pkg/pulsar/utils"
26- "github.com/stretchr/testify/assert"
2726)
2827
2928func TestDispatchRate (t * testing.T ) {
30- t . Skipf ( "Refactoring with gomega" )
29+ g := gomega . NewWithT ( t )
3130
3231 topicName := "persistent://public/default/test-dispatch-rate-topic"
3332 args := []string {"create" , topicName , "1" }
3433 _ , execErr , _ , _ := TestTopicCommands (CreateTopicCmd , args )
35- assert . Nil ( t , execErr )
34+ g . Expect ( execErr ). Should ( gomega . BeNil () )
3635
3736 setArgs := []string {"set-dispatch-rate" , topicName , "--msg-dispatch-rate" , "5" , "--byte-dispatch-rate" , "4" ,
3837 "--dispatch-rate-period" , "3" , "--relative-to-publish-rate" }
3938 setOut , execErr , _ , _ := TestTopicCommands (SetDispatchRateCmd , setArgs )
40- assert . Nil ( t , execErr )
41- assert . Equal ( t , setOut .String (), "Set message dispatch rate successfully for [" + topicName + "]\n " )
39+ g . Expect ( execErr ). Should ( gomega . BeNil () )
40+ g . Expect ( setOut .String ()). Should ( gomega . Equal ( "Set message dispatch rate successfully for [" + topicName + "]\n " ) )
4241
43- time .Sleep (time .Duration (1 ) * time .Second )
4442 getArgs := []string {"get-dispatch-rate" , topicName }
45- getOut , execErr , _ , _ := TestTopicCommands ( GetDispatchRateCmd , getArgs )
46- var dispatchRateData utils. DispatchRateData
47- err := json . Unmarshal ( getOut . Bytes (), & dispatchRateData )
48- if err != nil {
49- t . Fatal ( err )
50- }
51- assert . Nil ( t , execErr )
52- assert . Equal ( t , dispatchRateData .DispatchThrottlingRateInMsg , int64 (5 ))
53- assert . Equal ( t , dispatchRateData .DispatchThrottlingRateInByte , int64 (4 ))
54- assert . Equal ( t , dispatchRateData .RatePeriodInSecond , int64 ( 3 ))
55- assert . Equal ( t , dispatchRateData . RelativeToPublishRate , true )
43+ g . Eventually ( func ( g gomega. Gomega ) {
44+ getOut , execErr , _ , _ := TestTopicCommands ( GetDispatchRateCmd , getArgs )
45+ g . Expect ( execErr ). Should ( gomega . BeNil () )
46+ var dispatchRateData utils. DispatchRateData
47+ err := json . Unmarshal ( getOut . Bytes (), & dispatchRateData )
48+ g . Expect ( err ). Should ( gomega . BeNil ())
49+ g . Expect ( dispatchRateData . DispatchThrottlingRateInMsg ). Should ( gomega . Equal ( int64 ( 5 )) )
50+ g . Expect ( dispatchRateData .DispatchThrottlingRateInByte ). Should ( gomega . Equal ( int64 (4 ) ))
51+ g . Expect ( dispatchRateData .RatePeriodInSecond ). Should ( gomega . Equal ( int64 (3 ) ))
52+ g . Expect ( dispatchRateData .RelativeToPublishRate ). Should ( gomega . Equal ( true ))
53+ }). Should ( gomega . Succeed () )
5654
5755 setArgs = []string {"remove-dispatch-rate" , topicName }
5856 setOut , execErr , _ , _ = TestTopicCommands (RemoveDispatchRateCmd , setArgs )
59- assert . Nil ( t , execErr )
60- assert . Equal ( t , setOut .String (), "Remove message dispatch rate successfully for [" + topicName + "]\n " )
57+ g . Expect ( execErr ). Should ( gomega . BeNil () )
58+ g . Expect ( setOut .String ()). Should ( gomega . Equal ( "Remove message dispatch rate successfully for [" + topicName + "]\n " ) )
6159
62- time .Sleep (time .Duration (1 ) * time .Second )
63- getArgs = []string {"get-dispatch-rate" , topicName }
64- getOut , execErr , _ , _ = TestTopicCommands (GetDispatchRateCmd , getArgs )
65- err = json .Unmarshal (getOut .Bytes (), & dispatchRateData )
66- if err != nil {
67- t .Fatal (err )
68- }
69- assert .Nil (t , execErr )
70- assert .Equal (t , dispatchRateData .DispatchThrottlingRateInMsg , int64 (0 ))
71- assert .Equal (t , dispatchRateData .DispatchThrottlingRateInByte , int64 (0 ))
72- assert .Equal (t , dispatchRateData .RatePeriodInSecond , int64 (0 ))
73- assert .Equal (t , dispatchRateData .RelativeToPublishRate , false )
60+ g .Eventually (func (g gomega.Gomega ) {
61+ getOut , execErr , _ , _ := TestTopicCommands (GetDispatchRateCmd , getArgs )
62+ g .Expect (execErr ).Should (gomega .BeNil ())
63+ var dispatchRateData utils.DispatchRateData
64+ err := json .Unmarshal (getOut .Bytes (), & dispatchRateData )
65+ g .Expect (err ).Should (gomega .BeNil ())
66+ g .Expect (dispatchRateData .DispatchThrottlingRateInMsg ).Should (gomega .Equal (int64 (0 )))
67+ g .Expect (dispatchRateData .DispatchThrottlingRateInByte ).Should (gomega .Equal (int64 (0 )))
68+ g .Expect (dispatchRateData .RatePeriodInSecond ).Should (gomega .Equal (int64 (0 )))
69+ g .Expect (dispatchRateData .RelativeToPublishRate ).Should (gomega .Equal (false ))
70+ }).Should (gomega .Succeed ())
7471
7572 setArgs = []string {"set-dispatch-rate" , topicName , "--msg-dispatch-rate" , "5" , "--byte-dispatch-rate" , "4" ,
7673 "--dispatch-rate-period" , "3" }
7774 setOut , execErr , _ , _ = TestTopicCommands (SetDispatchRateCmd , setArgs )
78- assert . Nil ( t , execErr )
79- assert . Equal ( t , setOut .String (), "Set message dispatch rate successfully for [" + topicName + "]\n " )
75+ g . Expect ( execErr ). Should ( gomega . BeNil () )
76+ g . Expect ( setOut .String ()). Should ( gomega . Equal ( "Set message dispatch rate successfully for [" + topicName + "]\n " ) )
8077
81- time .Sleep (time .Duration (1 ) * time .Second )
82- getArgs = []string {"get-dispatch-rate" , topicName }
83- getOut , execErr , _ , _ = TestTopicCommands (GetDispatchRateCmd , getArgs )
84- err = json .Unmarshal (getOut .Bytes (), & dispatchRateData )
85- if err != nil {
86- t .Fatal (err )
87- }
88- assert .Nil (t , execErr )
89- assert .Equal (t , dispatchRateData .DispatchThrottlingRateInMsg , int64 (5 ))
90- assert .Equal (t , dispatchRateData .DispatchThrottlingRateInByte , int64 (4 ))
91- assert .Equal (t , dispatchRateData .RatePeriodInSecond , int64 (3 ))
92- assert .Equal (t , dispatchRateData .RelativeToPublishRate , false )
78+ g .Eventually (func (g gomega.Gomega ) {
79+ getOut , execErr , _ , _ := TestTopicCommands (GetDispatchRateCmd , getArgs )
80+ g .Expect (execErr ).Should (gomega .BeNil ())
81+ var dispatchRateData utils.DispatchRateData
82+ err := json .Unmarshal (getOut .Bytes (), & dispatchRateData )
83+ g .Expect (err ).Should (gomega .BeNil ())
84+ g .Expect (dispatchRateData .DispatchThrottlingRateInMsg ).Should (gomega .Equal (int64 (5 )))
85+ g .Expect (dispatchRateData .DispatchThrottlingRateInByte ).Should (gomega .Equal (int64 (4 )))
86+ g .Expect (dispatchRateData .RatePeriodInSecond ).Should (gomega .Equal (int64 (3 )))
87+ g .Expect (dispatchRateData .RelativeToPublishRate ).Should (gomega .Equal (false ))
88+ }).Should (gomega .Succeed ())
9389}
0 commit comments