@@ -154,6 +154,22 @@ func (s *RemoteSuite) TestFetchContext(c *C) {
154
154
URLs : []string {s .GetLocalRepositoryURL (fixtures .ByTag ("tags" ).One ())},
155
155
})
156
156
157
+ ctx , cancel := context .WithCancel (context .Background ())
158
+ defer cancel ()
159
+
160
+ err := r .FetchContext (ctx , & FetchOptions {
161
+ RefSpecs : []config.RefSpec {
162
+ config .RefSpec ("+refs/heads/master:refs/remotes/origin/master" ),
163
+ },
164
+ })
165
+ c .Assert (err , IsNil )
166
+ }
167
+
168
+ func (s * RemoteSuite ) TestFetchContextCanceled (c * C ) {
169
+ r := NewRemote (memory .NewStorage (), & config.RemoteConfig {
170
+ URLs : []string {s .GetLocalRepositoryURL (fixtures .ByTag ("tags" ).One ())},
171
+ })
172
+
157
173
ctx , cancel := context .WithCancel (context .Background ())
158
174
cancel ()
159
175
@@ -478,6 +494,35 @@ func (s *RemoteSuite) TestPushContext(c *C) {
478
494
URLs : []string {url },
479
495
})
480
496
497
+ ctx , cancel := context .WithCancel (context .Background ())
498
+ defer cancel ()
499
+
500
+ numGoroutines := runtime .NumGoroutine ()
501
+
502
+ err = r .PushContext (ctx , & PushOptions {
503
+ RefSpecs : []config.RefSpec {"refs/tags/*:refs/tags/*" },
504
+ })
505
+ c .Assert (err , IsNil )
506
+
507
+ // let the goroutine from pushHashes finish and check that the number of
508
+ // goroutines is the same as before
509
+ time .Sleep (100 * time .Millisecond )
510
+ c .Assert (runtime .NumGoroutine (), Equals , numGoroutines )
511
+ }
512
+
513
+ func (s * RemoteSuite ) TestPushContextCanceled (c * C ) {
514
+ url := c .MkDir ()
515
+ _ , err := PlainInit (url , true )
516
+ c .Assert (err , IsNil )
517
+
518
+ fs := fixtures .ByURL ("https://github.com/git-fixtures/tags.git" ).One ().DotGit ()
519
+ sto := filesystem .NewStorage (fs , cache .NewObjectLRUDefault ())
520
+
521
+ r := NewRemote (sto , & config.RemoteConfig {
522
+ Name : DefaultRemoteName ,
523
+ URLs : []string {url },
524
+ })
525
+
481
526
ctx , cancel := context .WithCancel (context .Background ())
482
527
cancel ()
483
528
0 commit comments