aboutsummaryrefslogtreecommitdiffstats
path: root/remote_test.go
diff options
context:
space:
mode:
authorAndrew Suffield <asuffield@gmail.com>2021-03-26 16:03:49 +0000
committerGitHub <noreply@github.com>2021-03-26 17:03:49 +0100
commite5bbc4d10904554dbc8fd5afd06f66814f7b173e (patch)
tree6a1508b51ede537c75896ba6650a8f5fb0ad09f8 /remote_test.go
parent1f328388192915476c68e5e0c8c1c818fd50fc6b (diff)
downloadgo-git-e5bbc4d10904554dbc8fd5afd06f66814f7b173e.tar.gz
plumbing: wire up contexts for Transport.AdvertisedReferences (#246)
* plumbing: wire up contexts for Transport.AdvertisedReferences * add more tests for context wiring
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