-
Notifications
You must be signed in to change notification settings - Fork 222
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf(fs/git): only fetch known or newly requested references
Signed-off-by: George MacRorie <[email protected]>
- Loading branch information
Showing
2 changed files
with
78 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -172,7 +172,7 @@ flags: | |
require.NoError(t, fi.Close()) | ||
|
||
// commit changes | ||
_, err = tree.Commit("chore: update features.yml", &git.CommitOptions{ | ||
_, err = tree.Commit("chore: update features.yml add foo and bar", &git.CommitOptions{ | ||
All: true, | ||
Author: &object.Signature{Email: "[email protected]", Name: "dev"}, | ||
}) | ||
|
@@ -185,18 +185,6 @@ flags: | |
RefSpecs: []config.RefSpec{"refs/heads/new-branch:refs/heads/new-branch"}, | ||
})) | ||
|
||
// wait until the snapshot is updated or | ||
// we timeout | ||
select { | ||
case <-ch: | ||
case <-time.After(time.Minute): | ||
t.Fatal("timed out waiting for snapshot") | ||
} | ||
|
||
require.NoError(t, err) | ||
|
||
t.Log("received new snapshot") | ||
|
||
require.NoError(t, store.View(ctx, "", func(s storage.ReadOnlyStore) error { | ||
_, err := s.GetFlag(ctx, storage.NewResource("production", "bar")) | ||
require.Error(t, err, "flag should not be found in default revision") | ||
|
@@ -209,11 +197,65 @@ flags: | |
return nil | ||
})) | ||
|
||
// should be able to fetch flag from previously unfetched reference | ||
require.NoError(t, store.View(ctx, "new-branch", func(s storage.ReadOnlyStore) error { | ||
_, err := s.GetFlag(ctx, storage.NewResource("production", "bar")) | ||
require.NoError(t, err, "flag should be present on new-branch") | ||
return nil | ||
})) | ||
|
||
// flag bar should not yet be present | ||
require.NoError(t, store.View(ctx, "new-branch", func(s storage.ReadOnlyStore) error { | ||
_, err := s.GetFlag(ctx, storage.NewResource("production", "baz")) | ||
require.Error(t, err, "flag should not be found in explicitly named new-branch revision") | ||
return nil | ||
})) | ||
|
||
// update features.yml, now with the bar flag | ||
fi, err = workdir.OpenFile("features.yml", os.O_TRUNC|os.O_RDWR, os.ModePerm) | ||
require.NoError(t, err) | ||
|
||
updated = []byte(`namespace: production | ||
flags: | ||
- key: foo | ||
name: Foo | ||
- key: bar | ||
name: Bar | ||
- key: baz | ||
name: Baz`) | ||
|
||
_, err = fi.Write(updated) | ||
require.NoError(t, err) | ||
require.NoError(t, fi.Close()) | ||
|
||
// commit changes | ||
_, err = tree.Commit("chore: update features.yml add baz", &git.CommitOptions{ | ||
All: true, | ||
Author: &object.Signature{Email: "[email protected]", Name: "dev"}, | ||
}) | ||
require.NoError(t, err) | ||
|
||
// push new commit | ||
require.NoError(t, repo.Push(&git.PushOptions{ | ||
Auth: &http.BasicAuth{Username: "root", Password: "password"}, | ||
RemoteName: "origin", | ||
RefSpecs: []config.RefSpec{"refs/heads/new-branch:refs/heads/new-branch"}, | ||
})) | ||
|
||
// we should expect to see a modified event now because | ||
// the new reference should be tracked | ||
select { | ||
case <-ch: | ||
case <-time.After(time.Minute): | ||
t.Fatal("timed out waiting for fetch") | ||
} | ||
|
||
// should be able to fetch flag bar now that it has been pushed | ||
require.NoError(t, store.View(ctx, "new-branch", func(s storage.ReadOnlyStore) error { | ||
_, err := s.GetFlag(ctx, storage.NewResource("production", "baz")) | ||
require.NoError(t, err, "flag should be present on new-branch") | ||
return nil | ||
})) | ||
} | ||
|
||
func Test_Store_View_WithSemverRevision(t *testing.T) { | ||
|