@@ -50,7 +50,7 @@ func TestReceive(t *testing.T) {
5050 c := NewCircuit ()
5151 pushLock := NewInMemoryRepositoryLock ()
5252 cleanerRef := cleaner .NewRef ()
53- cxt := runServer (& cfg , c , pushLock , cleanerRef , testingServerAddr , t )
53+ cxt := runServer (& cfg , c , pushLock , cleanerRef , testingServerAddr , time . Duration ( 0 ), t )
5454
5555 // Give server time to initialize.
5656 time .Sleep (200 * time .Millisecond )
@@ -107,7 +107,7 @@ func TestPush(t *testing.T) {
107107 c := NewCircuit ()
108108 pushLock := NewInMemoryRepositoryLock ()
109109 cleanerRef := cleaner .NewRef ()
110- runServer (& cfg , c , pushLock , cleanerRef , testingServerAddr , t )
110+ runServer (& cfg , c , pushLock , cleanerRef , testingServerAddr , 5 * time . Second , t )
111111
112112 // Give server time to initialize.
113113 time .Sleep (200 * time .Millisecond )
@@ -170,7 +170,7 @@ func TestManyConcurrentPushes(t *testing.T) {
170170 c := NewCircuit ()
171171 pushLock := NewInMemoryRepositoryLock ()
172172 cleanerRef := cleaner .NewRef ()
173- runServer (& cfg , c , pushLock , cleanerRef , testingServerAddr , t )
173+ runServer (& cfg , c , pushLock , cleanerRef , testingServerAddr , time . Duration ( 0 ), t )
174174 time .Sleep (200 * time .Millisecond )
175175 assert .Equal (t , c .State (), ClosedState , "circuit state" )
176176
@@ -225,7 +225,7 @@ func TestDelete(t *testing.T) {
225225 c := NewCircuit ()
226226 pushLock := NewInMemoryRepositoryLock ()
227227 cleanerRef := cleaner .NewRef ()
228- runServer (& cfg , c , pushLock , cleanerRef , testingServerAddr , t )
228+ runServer (& cfg , c , pushLock , cleanerRef , testingServerAddr , time . Duration ( 0 ), t )
229229
230230 // Give server time to initialize.
231231 time .Sleep (200 * time .Millisecond )
@@ -264,7 +264,15 @@ func sshTestingHostKey() (ssh.Signer, error) {
264264 return ssh .ParsePrivateKey ([]byte (testingHostKey ))
265265}
266266
267- func runServer (config * ssh.ServerConfig , c * Circuit , pushLock RepositoryLock , cleanerRef cleaner.Ref , testAddr string , t * testing.T ) cookoo.Context {
267+ func runServer (
268+ config * ssh.ServerConfig ,
269+ c * Circuit ,
270+ pushLock RepositoryLock ,
271+ cleanerRef cleaner.Ref ,
272+ testAddr string ,
273+ handlerSleepDur time.Duration ,
274+ t * testing.T ) cookoo.Context {
275+
268276 reg , router , cxt := cookoo .Cookoo ()
269277 cxt .Put (ServerConfig , config )
270278 cxt .Put (Address , testAddr )
@@ -305,7 +313,7 @@ func runServer(config *ssh.ServerConfig, c *Circuit, pushLock RepositoryLock, cl
305313 Does : []cookoo.Task {
306314 cookoo.Cmd {
307315 Name : "receive" ,
308- Fn : mockDummyReceive ,
316+ Fn : mockDummyReceive ( handlerSleepDur ) ,
309317 Using : []cookoo.Param {
310318 {Name : "request" , From : "cxt:request" },
311319 {Name : "channel" , From : "cxt:channel" },
@@ -343,14 +351,16 @@ func mockAuthKey(c cookoo.Context, p *cookoo.Params) (interface{}, cookoo.Interr
343351 return perm , nil
344352}
345353
346- func mockDummyReceive (c cookoo.Context , p * cookoo.Params ) (interface {}, cookoo.Interrupt ) {
347- channel := p .Get ("channel" , nil ).(ssh.Channel )
348- req := p .Get ("request" , nil ).(* ssh.Request )
349- time .Sleep (5 * time .Second )
350- channel .Write ([]byte ("OK" ))
351- sendExitStatus (0 , channel )
352- req .Reply (true , nil )
353- return nil , nil
354+ func mockDummyReceive (sleepDur time.Duration ) func (cookoo.Context , * cookoo.Params ) (interface {}, cookoo.Interrupt ) {
355+ return func (c cookoo.Context , p * cookoo.Params ) (interface {}, cookoo.Interrupt ) {
356+ channel := p .Get ("channel" , nil ).(ssh.Channel )
357+ req := p .Get ("request" , nil ).(* ssh.Request )
358+ time .Sleep (sleepDur )
359+ channel .Write ([]byte ("OK" ))
360+ sendExitStatus (0 , channel )
361+ req .Reply (true , nil )
362+ return nil , nil
363+ }
354364}
355365
356366// connMetadata mocks ssh.ConnMetadata for authentication.
0 commit comments