aboutsummaryrefslogtreecommitdiffstats
path: root/remote_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'remote_test.go')
-rw-r--r--remote_test.go49
1 files changed, 47 insertions, 2 deletions
diff --git a/remote_test.go b/remote_test.go
index bc05b7e..38f17ad 100644
--- a/remote_test.go
+++ b/remote_test.go
@@ -155,6 +155,22 @@ func (s *RemoteSuite) TestFetchContext(c *C) {
})
ctx, cancel := context.WithCancel(context.Background())
+ defer cancel()
+
+ err := r.FetchContext(ctx, &FetchOptions{
+ RefSpecs: []config.RefSpec{
+ config.RefSpec("+refs/heads/master:refs/remotes/origin/master"),
+ },
+ })
+ c.Assert(err, IsNil)
+}
+
+func (s *RemoteSuite) TestFetchContextCanceled(c *C) {
+ r := NewRemote(memory.NewStorage(), &config.RemoteConfig{
+ URLs: []string{s.GetLocalRepositoryURL(fixtures.ByTag("tags").One())},
+ })
+
+ ctx, cancel := context.WithCancel(context.Background())
cancel()
err := r.FetchContext(ctx, &FetchOptions{
@@ -162,7 +178,7 @@ func (s *RemoteSuite) TestFetchContext(c *C) {
config.RefSpec("+refs/heads/master:refs/remotes/origin/master"),
},
})
- c.Assert(err, NotNil)
+ c.Assert(err, Equals, context.Canceled)
}
func (s *RemoteSuite) TestFetchWithAllTags(c *C) {
@@ -479,6 +495,35 @@ func (s *RemoteSuite) TestPushContext(c *C) {
})
ctx, cancel := context.WithCancel(context.Background())
+ defer cancel()
+
+ numGoroutines := runtime.NumGoroutine()
+
+ err = r.PushContext(ctx, &PushOptions{
+ RefSpecs: []config.RefSpec{"refs/tags/*:refs/tags/*"},
+ })
+ c.Assert(err, IsNil)
+
+ // let the goroutine from pushHashes finish and check that the number of
+ // goroutines is the same as before
+ time.Sleep(100 * time.Millisecond)
+ c.Assert(runtime.NumGoroutine(), Equals, numGoroutines)
+}
+
+func (s *RemoteSuite) TestPushContextCanceled(c *C) {
+ url := c.MkDir()
+ _, err := PlainInit(url, true)
+ c.Assert(err, IsNil)
+
+ fs := fixtures.ByURL("https://github.com/git-fixtures/tags.git").One().DotGit()
+ sto := filesystem.NewStorage(fs, cache.NewObjectLRUDefault())
+
+ r := NewRemote(sto, &config.RemoteConfig{
+ Name: DefaultRemoteName,
+ URLs: []string{url},
+ })
+
+ ctx, cancel := context.WithCancel(context.Background())
cancel()
numGoroutines := runtime.NumGoroutine()
@@ -486,7 +531,7 @@ func (s *RemoteSuite) TestPushContext(c *C) {
err = r.PushContext(ctx, &PushOptions{
RefSpecs: []config.RefSpec{"refs/tags/*:refs/tags/*"},
})
- c.Assert(err, NotNil)
+ c.Assert(err, Equals, context.Canceled)
// let the goroutine from pushHashes finish and check that the number of
// goroutines is the same as before