@@ -22,6 +22,7 @@ import (
2222 "github.com/apache/pulsar-client-go/pulsaradmin/pkg/utils"
2323 "github.com/functionstream/functionstream/common"
2424 "github.com/functionstream/functionstream/lib"
25+ "github.com/functionstream/functionstream/lib/contube"
2526 "github.com/functionstream/functionstream/perf"
2627 "github.com/functionstream/functionstream/restclient"
2728 "github.com/functionstream/functionstream/server"
@@ -35,12 +36,10 @@ import (
3536
3637func BenchmarkStressForBasicFunc (b * testing.B ) {
3738 s := server .New (server .LoadConfigFromEnv ())
38- go s .Run ()
39+ svrCtx , svrCancel := context .WithCancel (context .Background ())
40+ go s .Run (svrCtx )
3941 defer func () {
40- err := s .Close ()
41- if err != nil {
42- b .Fatal (err )
43- }
42+ svrCancel ()
4443 }()
4544
4645 inputTopic := "test-input-" + strconv .Itoa (rand .Int ())
@@ -78,7 +77,7 @@ func BenchmarkStressForBasicFunc(b *testing.B) {
7877
7978 b .ReportAllocs ()
8079
81- ctx , cancel := context .WithDeadline (context .Background (), time .Now ().Add (3 * time .Second ))
80+ ctx , cancel := context .WithDeadline (context .Background (), time .Now ().Add (30 * time .Second ))
8281 defer cancel ()
8382
8483 profile := b .Name () + ".pprof"
@@ -95,28 +94,27 @@ func BenchmarkStressForBasicFunc(b *testing.B) {
9594 b .Fatal (err )
9695 }
9796
97+ <- s .WaitForReady (context .Background ())
9898 perf .New (pConfig ).Run (ctx )
9999
100100 pprof .StopCPUProfile ()
101101}
102102
103103func BenchmarkStressForBasicFuncWithMemoryQueue (b * testing.B ) {
104- memoryQueueFactory := lib .NewMemoryQueueFactory (context .Background ())
104+ memoryQueueFactory := contube .NewMemoryQueueFactory (context .Background ())
105105
106106 svrConf := & lib.Config {
107107 ListenAddr : common .DefaultAddr ,
108- QueueBuilder : func (ctx context.Context , config * lib.Config ) (lib. EventQueueFactory , error ) {
108+ QueueBuilder : func (ctx context.Context , config * lib.Config ) (contube. TubeFactory , error ) {
109109 return memoryQueueFactory , nil
110110 },
111111 }
112112
113113 s := server .New (svrConf )
114- go s .Run ()
114+ svrCtx , svrCancel := context .WithCancel (context .Background ())
115+ go s .Run (svrCtx )
115116 defer func () {
116- err := s .Close ()
117- if err != nil {
118- b .Fatal (err )
119- }
117+ svrCancel ()
120118 }()
121119
122120 inputTopic := "test-input-" + strconv .Itoa (rand .Int ())
@@ -132,14 +130,14 @@ func BenchmarkStressForBasicFuncWithMemoryQueue(b *testing.B) {
132130 Output : outputTopic ,
133131 Replicas : & replicas ,
134132 },
135- QueueBuilder : func (ctx context.Context , c * lib.Config ) (lib. EventQueueFactory , error ) {
133+ QueueBuilder : func (ctx context.Context , c * lib.Config ) (contube. TubeFactory , error ) {
136134 return memoryQueueFactory , nil
137135 },
138136 }
139137
140138 b .ReportAllocs ()
141139
142- ctx , cancel := context .WithDeadline (context .Background (), time .Now ().Add (3 * time .Second ))
140+ ctx , cancel := context .WithDeadline (context .Background (), time .Now ().Add (30 * time .Second ))
143141 defer cancel ()
144142
145143 profile := b .Name () + ".pprof"
@@ -156,6 +154,7 @@ func BenchmarkStressForBasicFuncWithMemoryQueue(b *testing.B) {
156154 b .Fatal (err )
157155 }
158156
157+ <- s .WaitForReady (context .Background ())
159158 perf .New (pConfig ).Run (ctx )
160159
161160 pprof .StopCPUProfile ()
0 commit comments