Skip to content

Commit

Permalink
add more tests for context wiring
Browse files Browse the repository at this point in the history
  • Loading branch information
asuffield committed Mar 15, 2021
1 parent 44faab6 commit bbd4c4f
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 0 deletions.
31 changes: 31 additions & 0 deletions plumbing/transport/http/upload_pack_test.go
@@ -1,8 +1,10 @@
package http

import (
"context"
"fmt"
"io/ioutil"
"net/url"
"os"
"path/filepath"

Expand Down Expand Up @@ -103,3 +105,32 @@ func (s *UploadPackSuite) TestAdvertisedReferencesRedirectSchema(c *C) {
url := session.(*upSession).endpoint.String()
c.Assert(url, Equals, "https://github.com/git-fixtures/basic")
}

func (s *UploadPackSuite) TestAdvertisedReferencesContext(c *C) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
endpoint, _ := transport.NewEndpoint("http://github.com/git-fixtures/basic")

session, err := s.Client.NewUploadPackSession(endpoint, s.EmptyAuth)
c.Assert(err, IsNil)

info, err := session.AdvertisedReferencesContext(ctx)
c.Assert(err, IsNil)
c.Assert(info, NotNil)

url := session.(*upSession).endpoint.String()
c.Assert(url, Equals, "https://github.com/git-fixtures/basic")
}

func (s *UploadPackSuite) TestAdvertisedReferencesContextCanceled(c *C) {
ctx, cancel := context.WithCancel(context.Background())
cancel()
endpoint, _ := transport.NewEndpoint("http://github.com/git-fixtures/basic")

session, err := s.Client.NewUploadPackSession(endpoint, s.EmptyAuth)
c.Assert(err, IsNil)

info, err := session.AdvertisedReferencesContext(ctx)
c.Assert(err, DeepEquals, &url.Error{Op: "Get", URL: "http://github.com/git-fixtures/basic/info/refs?service=git-upload-pack", Err: context.Canceled})
c.Assert(info, IsNil)
}
45 changes: 45 additions & 0 deletions remote_test.go
Expand Up @@ -154,6 +154,22 @@ func (s *RemoteSuite) TestFetchContext(c *C) {
URLs: []string{s.GetLocalRepositoryURL(fixtures.ByTag("tags").One())},
})

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()

Expand Down Expand Up @@ -478,6 +494,35 @@ func (s *RemoteSuite) TestPushContext(c *C) {
URLs: []string{url},
})

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()

Expand Down

0 comments on commit bbd4c4f

Please sign in to comment.