Skip to content
This repository was archived by the owner on Sep 30, 2024. It is now read-only.

Commit a3cde3f

Browse files
committed
gitserver: Simplify clone and update
Those two used to have separate mechanisms for locking and for making sure the operation keeps going in the background. This PR unifies those two where possible. Test plan: The clone test covers this pretty well, and I made a few adjustments there to cover the new behavior. Also, E2E tests will cover clone failures.
1 parent 52c8bc1 commit a3cde3f

File tree

5 files changed

+113
-255
lines changed

5 files changed

+113
-255
lines changed

cmd/gitserver/internal/integration_tests/clone_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,8 @@ func TestClone_Fail(t *testing.T) {
200200
require.Contains(t, err.Error(), "error cloning repo: repo github.com/test/repo not cloneable:")
201201
require.Contains(t, err.Error(), "exit status 128")
202202

203-
// No lock should have been acquired.
204-
mockassert.NotCalled(t, locker.TryAcquireFunc)
203+
mockassert.CalledOnce(t, locker.TryAcquireFunc)
204+
mockassert.CalledOnce(t, lock.ReleaseFunc)
205205

206206
// Check we reported an error.
207207
// Check that it was called exactly once total.
@@ -237,13 +237,13 @@ func TestClone_Fail(t *testing.T) {
237237
require.Contains(t, err.Error(), "failed to clone github.com/test/repo: clone failed. Output: Creating bare repo\nCreated bare repo at")
238238

239239
// Should have acquired a lock.
240-
mockassert.CalledOnce(t, locker.TryAcquireFunc)
240+
mockassert.CalledN(t, locker.TryAcquireFunc, 2)
241241
// Should have reported status. 7 lines is the output git currently produces.
242242
// This number might need to be adjusted over time, but before doing so please
243243
// check that the calls actually use the args you would expect them to use.
244244
mockassert.CalledN(t, lock.SetStatusFunc, 7)
245245
// Should have released the lock.
246-
mockassert.CalledOnce(t, lock.ReleaseFunc)
246+
mockassert.CalledN(t, lock.ReleaseFunc, 2)
247247

248248
// Check it was set to cloning first, then uncloned again (since clone failed).
249249
mockassert.CalledN(t, gsStore.SetCloneStatusFunc, 2)

cmd/gitserver/internal/lock.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ type RepositoryLock interface {
2020
// When a repository is locked, only the owner of the lock is allowed to perform
2121
// writing operations against it.
2222
//
23-
// The main use of RepositoryLocker is to prevent concurrent clones. However,
24-
// it is also used during maintenance tasks such as recloning/migrating/etc.
23+
// The main use of RepositoryLocker is to prevent concurrent fetches.
2524
type RepositoryLocker interface {
2625
// TryAcquire acquires the lock for repo. If it is already held, ok is false
2726
// and lock is nil. Otherwise a non-nil lock is returned and true. When

cmd/gitserver/internal/main_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ func runCmd(t *testing.T, dir string, cmd string, arg ...string) string {
3939
"GIT_AUTHOR_NAME=a",
4040
4141
}
42-
b, err := c.CombinedOutput()
42+
b, err := c.Output()
4343
if err != nil {
4444
t.Fatalf("%s %s failed: %s\nOutput: %s", cmd, strings.Join(arg, " "), err, b)
4545
}

0 commit comments

Comments
 (0)