[gold] Rename expectations.Label as expectations.LabelInt.
Step 2 of the plan outlined in skbug.com/10522.
Bug: skia:10522
Change-Id: I1acef843f288e6092f2eb9313dda56d279203cff
Reviewed-on: https://skia-review.googlesource.com/c/buildbot/+/304859
Commit-Queue: Leandro Lovisolo <lovisolo@google.com>
Reviewed-by: Kevin Lubick <kjlubick@google.com>
diff --git a/gold-client/go/goldclient/goldclient.go b/gold-client/go/goldclient/goldclient.go
index 4f2f21e..0645b21 100644
--- a/gold-client/go/goldclient/goldclient.go
+++ b/gold-client/go/goldclient/goldclient.go
@@ -454,10 +454,10 @@
func (c *CloudClient) matchImageAgainstBaseline(testName types.TestName, traceId tiling.TraceID, imageBytes []byte, imageHash types.Digest, optionalKeys map[string]string) (bool, imgmatching.AlgorithmName, error) {
// First we check whether the digest is a known positive or negative, regardless of the specified
// image matching algorithm.
- if c.resultState.Expectations[testName][imageHash] == expectations.Positive {
+ if c.resultState.Expectations[testName][imageHash] == expectations.PositiveInt {
return true, imgmatching.ExactMatching, nil
}
- if c.resultState.Expectations[testName][imageHash] == expectations.Negative {
+ if c.resultState.Expectations[testName][imageHash] == expectations.NegativeInt {
return false, imgmatching.ExactMatching, nil
}
@@ -852,7 +852,7 @@
return stringifyBaseline(c.resultState.Expectations), nil
}
-func stringifyBaseline(b map[types.TestName]map[types.Digest]expectations.Label) string {
+func stringifyBaseline(b map[types.TestName]map[types.Digest]expectations.LabelInt) string {
names := make([]string, 0, len(b))
for testName := range b {
names = append(names, string(testName))
diff --git a/gold-client/go/goldclient/goldclient_test.go b/gold-client/go/goldclient/goldclient_test.go
index 9fe63a8..76633c4 100644
--- a/gold-client/go/goldclient/goldclient_test.go
+++ b/gold-client/go/goldclient/goldclient_test.go
@@ -93,8 +93,8 @@
assert.Len(t, bl, 1, "only one test")
digests := bl["ThisIsTheOnlyTest"]
assert.Len(t, digests, 2, "two previously seen images")
- assert.Equal(t, expectations.Negative, digests["badbadbad1325855590527db196112e0"])
- assert.Equal(t, expectations.Positive, digests["beef00d3a1527db19619ec12a4e0df68"])
+ assert.Equal(t, expectations.NegativeInt, digests["badbadbad1325855590527db196112e0"])
+ assert.Equal(t, expectations.PositiveInt, digests["beef00d3a1527db19619ec12a4e0df68"])
assert.Equal(t, testIssueID, goldClient.resultState.SharedConfig.ChangeListID)
@@ -136,8 +136,8 @@
assert.Len(t, bl, 1, "only one test")
digests := bl["ThisIsTheOnlyTest"]
assert.Len(t, digests, 2, "two previously seen images")
- assert.Equal(t, expectations.Negative, digests["badbadbad1325855590527db196112e0"])
- assert.Equal(t, expectations.Positive, digests["beef00d3a1527db19619ec12a4e0df68"])
+ assert.Equal(t, expectations.NegativeInt, digests["badbadbad1325855590527db196112e0"])
+ assert.Equal(t, expectations.PositiveInt, digests["beef00d3a1527db19619ec12a4e0df68"])
assert.Equal(t, "", goldClient.resultState.SharedConfig.ChangeListID)
@@ -1519,9 +1519,9 @@
const testName = types.TestName("my_test")
const digest = types.Digest("11111111111111111111111111111111")
- const unlabeled = expectations.Label(-1) // Sentinel value.
+ const unlabeled = expectations.LabelInt(-1) // Sentinel value.
- test := func(name string, label expectations.Label, want bool) {
+ test := func(name string, label expectations.LabelInt, want bool) {
t.Run(name, func(t *testing.T) {
goldClient, cleanup, _, _ := makeGoldClientForMatchImageAgainstBaselineTests(t)
defer cleanup()
@@ -1543,9 +1543,9 @@
})
}
- test("image label positive, returns true", expectations.Positive, true)
- test("image label negative, returns false", expectations.Negative, false)
- test("image label untriaged, returns false", expectations.Untriaged, false)
+ test("image label positive, returns true", expectations.PositiveInt, true)
+ test("image label negative, returns false", expectations.NegativeInt, false)
+ test("image label untriaged, returns false", expectations.UntriagedInt, false)
test("image unlabeled, returns false", unlabeled, false)
}
@@ -1554,9 +1554,9 @@
const testName = types.TestName("my_test")
const digest = types.Digest("11111111111111111111111111111111")
- const unlabeled = expectations.Label(-1) // Sentinel value.
+ const unlabeled = expectations.LabelInt(-1) // Sentinel value.
- test := func(name string, label expectations.Label, want bool) {
+ test := func(name string, label expectations.LabelInt, want bool) {
t.Run(name, func(t *testing.T) {
goldClient, cleanup, _, _ := makeGoldClientForMatchImageAgainstBaselineTests(t)
defer cleanup()
@@ -1582,16 +1582,16 @@
})
}
- test("image labeled positive, returns true", expectations.Positive, true)
- test("image labeled negative, returns false", expectations.Negative, false)
- test("image labeled untriaged, returns false", expectations.Untriaged, false)
+ test("image labeled positive, returns true", expectations.PositiveInt, true)
+ test("image labeled negative, returns false", expectations.NegativeInt, false)
+ test("image labeled untriaged, returns false", expectations.UntriagedInt, false)
test("image unlabeled, returns false", unlabeled, false)
}
func TestCloudClient_MatchImageAgainstBaseline_FuzzyMatching_ImageAlreadyLabeled_Success(t *testing.T) {
unittest.MediumTest(t) // This test reads/writes a small amount of data from/to disk.
- test := func(name string, label expectations.Label, want bool) {
+ test := func(name string, label expectations.LabelInt, want bool) {
t.Run(name, func(t *testing.T) {
goldClient, cleanup, _, _ := makeGoldClientForMatchImageAgainstBaselineTests(t)
defer cleanup()
@@ -1618,8 +1618,8 @@
})
}
- test("labeled positive, returns true", expectations.Positive, true)
- test("labeled negative, returns false", expectations.Negative, false)
+ test("labeled positive, returns true", expectations.PositiveInt, true)
+ test("labeled negative, returns false", expectations.NegativeInt, false)
}
func TestCloudClient_MatchImageAgainstBaseline_FuzzyMatching_UntriagedImage_Success(t *testing.T) {
@@ -1775,7 +1775,7 @@
func TestCloudClient_MatchImageAgainstBaseline_SobelFuzzyMatching_ImageAlreadyLabeled_Success(t *testing.T) {
unittest.MediumTest(t) // This test reads/writes a small amount of data from/to disk.
- test := func(name string, label expectations.Label, want bool) {
+ test := func(name string, label expectations.LabelInt, want bool) {
t.Run(name, func(t *testing.T) {
goldClient, cleanup, _, _ := makeGoldClientForMatchImageAgainstBaselineTests(t)
defer cleanup()
@@ -1803,8 +1803,8 @@
})
}
- test("labeled positive, returns true", expectations.Positive, true)
- test("labeled negative, returns false", expectations.Negative, false)
+ test("labeled positive, returns true", expectations.PositiveInt, true)
+ test("labeled negative, returns false", expectations.NegativeInt, false)
}
func TestCloudClient_MatchImageAgainstBaseline_SobelFuzzyMatching_UntriagedImage_Success(t *testing.T) {
diff --git a/golden/cmd/fs_expstore_migrator/main.go b/golden/cmd/fs_expstore_migrator/main.go
index ae40806..5fdae15 100644
--- a/golden/cmd/fs_expstore_migrator/main.go
+++ b/golden/cmd/fs_expstore_migrator/main.go
@@ -87,12 +87,12 @@
}
type v2ExpectationEntry struct {
- Grouping types.TestName `firestore:"grouping"`
- Digest types.Digest `firestore:"digest"`
- Label expectations.Label `firestore:"label"`
- Updated time.Time `firestore:"updated"`
- CRSAndCLID string `firestore:"crs_cl_id"`
- LastUsed time.Time `firestore:"last_used"`
+ Grouping types.TestName `firestore:"grouping"`
+ Digest types.Digest `firestore:"digest"`
+ Label expectations.LabelInt `firestore:"label"`
+ Updated time.Time `firestore:"updated"`
+ CRSAndCLID string `firestore:"crs_cl_id"`
+ LastUsed time.Time `firestore:"last_used"`
}
type v2TriageRecord struct {
@@ -104,11 +104,11 @@
}
type v2TriageChange struct {
- RecordID string `firestore:"record_id"`
- Grouping types.TestName `firestore:"grouping"`
- Digest types.Digest `firestore:"digest"`
- LabelBefore expectations.Label `firestore:"before"`
- LabelAfter expectations.Label `firestore:"after"`
+ RecordID string `firestore:"record_id"`
+ Grouping types.TestName `firestore:"grouping"`
+ Digest types.Digest `firestore:"digest"`
+ LabelBefore expectations.LabelInt `firestore:"before"`
+ LabelAfter expectations.LabelInt `firestore:"after"`
}
func (v v2Impl) loadExpectationEntries(ctx context.Context) ([]v2ExpectationEntry, error) {
@@ -224,9 +224,9 @@
}
type v3TriageRange struct {
- FirstIndex int `firestore:"first_index"`
- LastIndex int `firestore:"last_index"`
- Label expectations.Label `firestore:"label"`
+ FirstIndex int `firestore:"first_index"`
+ LastIndex int `firestore:"last_index"`
+ Label expectations.LabelInt `firestore:"label"`
}
type v3TriageRecord struct {
@@ -238,11 +238,11 @@
type v3ExpectationChange struct {
// RecordID refers to a document in the records collection.
- RecordID string `firestore:"record_id"`
- Grouping types.TestName `firestore:"grouping"`
- Digest types.Digest `firestore:"digest"`
- AffectedRange v3TriageRange `firestore:"affected_range"`
- LabelBefore expectations.Label `firestore:"label_before"`
+ RecordID string `firestore:"record_id"`
+ Grouping types.TestName `firestore:"grouping"`
+ Digest types.Digest `firestore:"digest"`
+ AffectedRange v3TriageRange `firestore:"affected_range"`
+ LabelBefore expectations.LabelInt `firestore:"label_before"`
}
func (v v3Impl) migrateAndStoreEntries(ctx context.Context, oldEntries []v2ExpectationEntry) error {
diff --git a/golden/go/baseline/simple_baseliner/simple_baseliner_test.go b/golden/go/baseline/simple_baseliner/simple_baseliner_test.go
index 0b768d3..d1a4d89 100644
--- a/golden/go/baseline/simple_baseliner/simple_baseliner_test.go
+++ b/golden/go/baseline/simple_baseliner/simple_baseliner_test.go
@@ -86,18 +86,18 @@
// with additionalTriages overwriting existing expectations, if applicable.
assert.Equal(t, expectations.Baseline{
"brand-new-test": {
- IotaNewDigest: expectations.Positive,
- KappaNewDigest: expectations.Negative,
+ IotaNewDigest: expectations.PositiveInt,
+ KappaNewDigest: expectations.NegativeInt,
},
// AlphaTest should be unchanged from the master baseline.
three_devices.AlphaTest: {
- three_devices.AlphaPositiveDigest: expectations.Positive,
- three_devices.AlphaNegativeDigest: expectations.Negative,
+ three_devices.AlphaPositiveDigest: expectations.PositiveInt,
+ three_devices.AlphaNegativeDigest: expectations.NegativeInt,
},
three_devices.BetaTest: {
- MuNewDigest: expectations.Positive,
- three_devices.BetaPositiveDigest: expectations.Negative,
- three_devices.BetaUntriagedDigest: expectations.Positive,
+ MuNewDigest: expectations.PositiveInt,
+ three_devices.BetaPositiveDigest: expectations.NegativeInt,
+ three_devices.BetaUntriagedDigest: expectations.PositiveInt,
},
}, b.Expectations)
diff --git a/golden/go/expectations/cleanup/cleanup.go b/golden/go/expectations/cleanup/cleanup.go
index f0fa3d6..b9b1fab 100644
--- a/golden/go/expectations/cleanup/cleanup.go
+++ b/golden/go/expectations/cleanup/cleanup.go
@@ -101,7 +101,7 @@
func cleanup(ctx context.Context, gc expectations.GarbageCollector, policy Policy, now time.Time) error {
posMax := policy.PositiveMaxLastUsed
if posMax > 0 {
- if n, err := gc.MarkUnusedEntriesForGC(ctx, expectations.Positive, now.Add(-posMax)); err != nil {
+ if n, err := gc.MarkUnusedEntriesForGC(ctx, expectations.PositiveInt, now.Add(-posMax)); err != nil {
return skerr.Wrapf(err, "untriaging positive expectation entries before %s", now.Add(-posMax))
} else {
sklog.Infof("%d positive expectations have aged out", n)
@@ -110,7 +110,7 @@
negMax := policy.NegativeMaxLastUsed
if negMax > 0 {
- if n, err := gc.MarkUnusedEntriesForGC(ctx, expectations.Negative, now.Add(-negMax)); err != nil {
+ if n, err := gc.MarkUnusedEntriesForGC(ctx, expectations.NegativeInt, now.Add(-negMax)); err != nil {
return skerr.Wrapf(err, "untriaging negative expectation entries before %s", now.Add(-negMax))
} else {
sklog.Infof("%d negative expectations have aged out", n)
diff --git a/golden/go/expectations/cleanup/cleanup_test.go b/golden/go/expectations/cleanup/cleanup_test.go
index eb4ea12..c079f25 100644
--- a/golden/go/expectations/cleanup/cleanup_test.go
+++ b/golden/go/expectations/cleanup/cleanup_test.go
@@ -133,7 +133,7 @@
oneHourAgo := mock.MatchedBy(func(ts time.Time) bool {
return now.Sub(ts) == time.Hour
})
- mc.On("MarkUnusedEntriesForGC", testutils.AnyContext, expectations.Positive, oneHourAgo).Return(0, nil)
+ mc.On("MarkUnusedEntriesForGC", testutils.AnyContext, expectations.PositiveInt, oneHourAgo).Return(0, nil)
mc.On("GarbageCollect", testutils.AnyContext).Return(0, nil)
positiveOnlyPolicy := Policy{
@@ -154,7 +154,7 @@
twoHoursAgo := mock.MatchedBy(func(ts time.Time) bool {
return now.Sub(ts) == 2*time.Hour
})
- mc.On("MarkUnusedEntriesForGC", testutils.AnyContext, expectations.Negative, twoHoursAgo).Return(0, nil)
+ mc.On("MarkUnusedEntriesForGC", testutils.AnyContext, expectations.NegativeInt, twoHoursAgo).Return(0, nil)
mc.On("GarbageCollect", testutils.AnyContext).Return(0, nil)
negativeOnlyPolicy := Policy{
@@ -178,8 +178,8 @@
oneHourAgo := mock.MatchedBy(func(ts time.Time) bool {
return now.Sub(ts) == time.Hour
})
- mc.On("MarkUnusedEntriesForGC", testutils.AnyContext, expectations.Negative, twoHoursAgo).Return(0, nil)
- mc.On("MarkUnusedEntriesForGC", testutils.AnyContext, expectations.Positive, oneHourAgo).Return(0, nil)
+ mc.On("MarkUnusedEntriesForGC", testutils.AnyContext, expectations.NegativeInt, twoHoursAgo).Return(0, nil)
+ mc.On("MarkUnusedEntriesForGC", testutils.AnyContext, expectations.PositiveInt, oneHourAgo).Return(0, nil)
mc.On("GarbageCollect", testutils.AnyContext).Return(0, nil)
policy := Policy{
diff --git a/golden/go/expectations/expectations.go b/golden/go/expectations/expectations.go
index c05d7d0..0ddf0c7 100644
--- a/golden/go/expectations/expectations.go
+++ b/golden/go/expectations/expectations.go
@@ -27,7 +27,7 @@
// Baseline is a simplified view of the Expectations, suitable for JSON encoding. A Baseline only
// has entries with positive and negative labels (i.e. no untriaged entries).
-type Baseline map[types.TestName]map[types.Digest]Label
+type Baseline map[types.TestName]map[types.Digest]LabelInt
// ReadOnly is an interface with the non-mutating functions of Expectations.
// By using this instead of Expectations, we can make fewer copies, helping performance.
@@ -214,7 +214,7 @@
// done.
baseline := Baseline{}
for testName, digestToLabelStrMap := range n.labels {
- digestToLabelMap := map[types.Digest]Label{}
+ digestToLabelMap := map[types.Digest]LabelInt{}
for digest, labelStr := range digestToLabelStrMap {
digestToLabelMap[digest] = LabelFromString(labelStr)
}
diff --git a/golden/go/expectations/expectations_test.go b/golden/go/expectations/expectations_test.go
index 88ff619..edf88ec 100644
--- a/golden/go/expectations/expectations_test.go
+++ b/golden/go/expectations/expectations_test.go
@@ -227,12 +227,12 @@
expectedOutput := Baseline{
"beta": {
- "hash1": Positive,
- "hash3": Negative,
- "hash4": Positive,
+ "hash1": PositiveInt,
+ "hash3": NegativeInt,
+ "hash4": PositiveInt,
},
"alpha": {
- "hashA": Negative,
+ "hashA": NegativeInt,
},
}
require.Equal(t, expectedOutput, input.AsBaseline())
diff --git a/golden/go/expectations/fs_expectationstore/fs_expstore.go b/golden/go/expectations/fs_expectationstore/fs_expstore.go
index 38a332c..492ed68 100644
--- a/golden/go/expectations/fs_expectationstore/fs_expstore.go
+++ b/golden/go/expectations/fs_expectationstore/fs_expstore.go
@@ -135,17 +135,17 @@
// expectationChange represents the changing of a single expectation entry.
type expectationChange struct {
// RecordID refers to a document in the records collection.
- RecordID string `firestore:"record_id"`
- Grouping types.TestName `firestore:"grouping"`
- Digest types.Digest `firestore:"digest"`
- AffectedRange triageRange `firestore:"affected_range"`
- LabelBefore expectations.Label `firestore:"label_before"`
+ RecordID string `firestore:"record_id"`
+ Grouping types.TestName `firestore:"grouping"`
+ Digest types.Digest `firestore:"digest"`
+ AffectedRange triageRange `firestore:"affected_range"`
+ LabelBefore expectations.LabelInt `firestore:"label_before"`
}
type triageRange struct {
- FirstIndex int `firestore:"first_index"`
- LastIndex int `firestore:"last_index"`
- Label expectations.Label `firestore:"label"`
+ FirstIndex int `firestore:"first_index"`
+ LastIndex int `firestore:"last_index"`
+ Label expectations.LabelInt `firestore:"label"`
}
// triageRecord represents a group of changes made in a single triage action by a user.
@@ -412,7 +412,7 @@
LastIndex: lastIdx,
Label: expectations.LabelFromString(d.Label),
}
- previousLabel := expectations.Untriaged
+ previousLabel := expectations.UntriagedInt
replacedRange := false
// TODO(kjlubick): if needed, this could be a binary search, but since there will be < 20
// ranges for almost all entries, it probably doesn't matter.
@@ -781,7 +781,7 @@
}
// MarkUnusedEntriesForGC implements the expectations.GarbageCollector interface.
-func (s *Store) MarkUnusedEntriesForGC(ctx context.Context, label expectations.Label, ts time.Time) (int, error) {
+func (s *Store) MarkUnusedEntriesForGC(ctx context.Context, label expectations.LabelInt, ts time.Time) (int, error) {
if s.partition != masterPartition {
return 0, skerr.Fmt("Cannot call UpdateLastUsed except on the master partition")
}
diff --git a/golden/go/expectations/fs_expectationstore/fs_expstore_test.go b/golden/go/expectations/fs_expectationstore/fs_expstore_test.go
index 5df0da0..d444c39 100644
--- a/golden/go/expectations/fs_expectationstore/fs_expstore_test.go
+++ b/golden/go/expectations/fs_expectationstore/fs_expstore_test.go
@@ -182,7 +182,7 @@
masterStore := New(c, nil, ReadWrite)
clStore := masterStore.ForChangeList("123", "github") // These are arbitrary
- putEntry(ctx, t, clStore, data.AlphaTest, data.AlphaPositiveDigest, expectations.Positive, userOne)
+ putEntry(ctx, t, clStore, data.AlphaTest, data.AlphaPositiveDigest, expectations.PositiveInt, userOne)
clExps, err := clStore.GetCopy(ctx)
require.NoError(t, err)
@@ -209,7 +209,7 @@
masterStore := New(c, nil, ReadWrite)
require.NoError(t, masterStore.Initialize(ctx))
- putEntry(ctx, t, masterStore, data.AlphaTest, data.AlphaPositiveDigest, expectations.Positive, userOne)
+ putEntry(ctx, t, masterStore, data.AlphaTest, data.AlphaPositiveDigest, expectations.PositiveInt, userOne)
// Wait for the query snapshot to show up in the RAM cache.
assert.Eventually(t, func() bool {
@@ -250,9 +250,9 @@
// Initialize store with some expectations.
masterStore := New(c, nil, ReadWrite)
- putEntry(ctx, t, masterStore, data.AlphaTest, data.AlphaPositiveDigest, expectations.Positive, userOne)
- putEntry(ctx, t, masterStore, data.AlphaTest, data.AlphaNegativeDigest, expectations.Negative, userOne)
- putEntry(ctx, t, masterStore, data.AlphaTest, firstPositiveThenUntriaged, expectations.Positive, userOne)
+ putEntry(ctx, t, masterStore, data.AlphaTest, data.AlphaPositiveDigest, expectations.PositiveInt, userOne)
+ putEntry(ctx, t, masterStore, data.AlphaTest, data.AlphaNegativeDigest, expectations.NegativeInt, userOne)
+ putEntry(ctx, t, masterStore, data.AlphaTest, firstPositiveThenUntriaged, expectations.PositiveInt, userOne)
// Create a read-only store and assert the cache is empty before we call Initialize.
readOnly := New(c, nil, ReadOnly)
@@ -272,8 +272,8 @@
assert.Equal(t, expectations.PositiveStr, roExps.Classification(data.AlphaTest, firstPositiveThenUntriaged))
// This should update the existing entry, leaving us with 4 total entries, not 5
- putEntry(ctx, t, masterStore, data.AlphaTest, firstPositiveThenUntriaged, expectations.Untriaged, userOne)
- putEntry(ctx, t, masterStore, data.BetaTest, data.BetaPositiveDigest, expectations.Positive, userOne)
+ putEntry(ctx, t, masterStore, data.AlphaTest, firstPositiveThenUntriaged, expectations.UntriagedInt, userOne)
+ putEntry(ctx, t, masterStore, data.BetaTest, data.BetaPositiveDigest, expectations.PositiveInt, userOne)
assert.Eventually(t, func() bool {
readOnly.entryCacheMutex.RLock()
@@ -374,7 +374,7 @@
masterStore := New(c, nil, ReadWrite)
require.NoError(t, masterStore.Initialize(ctx))
- putEntry(ctx, t, masterStore, data.AlphaTest, data.AlphaPositiveDigest, expectations.Negative, userTwo)
+ putEntry(ctx, t, masterStore, data.AlphaTest, data.AlphaPositiveDigest, expectations.NegativeInt, userTwo)
clStore := masterStore.ForChangeList("117", "gerrit") // arbitrary cl id
// Check that it starts out blank.
@@ -383,11 +383,11 @@
require.True(t, clExps.Empty())
// Add to the CL expectations
- putEntry(ctx, t, clStore, data.AlphaTest, data.AlphaPositiveDigest, expectations.Positive, userOne)
- putEntry(ctx, t, clStore, data.BetaTest, data.BetaPositiveDigest, expectations.Positive, userTwo)
+ putEntry(ctx, t, clStore, data.AlphaTest, data.AlphaPositiveDigest, expectations.PositiveInt, userOne)
+ putEntry(ctx, t, clStore, data.BetaTest, data.BetaPositiveDigest, expectations.PositiveInt, userTwo)
// Add to the master expectations
- putEntry(ctx, t, masterStore, data.AlphaTest, data.AlphaNegativeDigest, expectations.Negative, userOne)
+ putEntry(ctx, t, masterStore, data.AlphaTest, data.AlphaNegativeDigest, expectations.NegativeInt, userOne)
// Wait for the entries to sync.
assert.Eventually(t, func() bool {
@@ -589,7 +589,7 @@
// This will wait for the firestore query snapshots to update the cache to have the entry we care
// about to have the given label.
- waitForCacheToBe := func(label expectations.Label) {
+ waitForCacheToBe := func(label expectations.LabelInt) {
require.Eventually(t, func() bool {
masterStore.entryCacheMutex.RLock()
defer masterStore.entryCacheMutex.RUnlock()
@@ -603,20 +603,20 @@
}, 10*time.Second, 100*time.Millisecond)
}
- putEntry(ctx, t, masterStore, theEntry.Grouping, theEntry.Digest, expectations.Positive, userOne)
- waitForCacheToBe(expectations.Positive)
+ putEntry(ctx, t, masterStore, theEntry.Grouping, theEntry.Digest, expectations.PositiveInt, userOne)
+ waitForCacheToBe(expectations.PositiveInt)
fakeNow = fakeNow.Add(time.Minute)
- putEntry(ctx, t, masterStore, theEntry.Grouping, theEntry.Digest, expectations.Negative, userOne)
- waitForCacheToBe(expectations.Negative)
+ putEntry(ctx, t, masterStore, theEntry.Grouping, theEntry.Digest, expectations.NegativeInt, userOne)
+ waitForCacheToBe(expectations.NegativeInt)
fakeNow = fakeNow.Add(time.Minute)
- putEntry(ctx, t, masterStore, theEntry.Grouping, theEntry.Digest, expectations.Untriaged, userTwo)
- waitForCacheToBe(expectations.Untriaged)
+ putEntry(ctx, t, masterStore, theEntry.Grouping, theEntry.Digest, expectations.UntriagedInt, userTwo)
+ waitForCacheToBe(expectations.UntriagedInt)
fakeNow = fakeNow.Add(time.Minute)
- putEntry(ctx, t, masterStore, theEntry.Grouping, theEntry.Digest, expectations.Positive, userTwo)
- waitForCacheToBe(expectations.Positive)
+ putEntry(ctx, t, masterStore, theEntry.Grouping, theEntry.Digest, expectations.PositiveInt, userTwo)
+ waitForCacheToBe(expectations.PositiveInt)
xth, err := masterStore.GetTriageHistory(ctx, theEntry.Grouping, theEntry.Digest)
require.NoError(t, err)
@@ -715,7 +715,7 @@
return fakeNow
}
- putEntry(ctx, t, masterStore, data.AlphaTest, data.AlphaPositiveDigest, expectations.Positive, userOne)
+ putEntry(ctx, t, masterStore, data.AlphaTest, data.AlphaPositiveDigest, expectations.PositiveInt, userOne)
secondTime := time.Date(2020, time.March, 14, 2, 3, 4, 0, time.UTC)
fakeNow = secondTime
@@ -788,7 +788,7 @@
return fakeNow
}
- putEntry(ctx, t, masterStore, data.AlphaTest, data.AlphaPositiveDigest, expectations.Positive, userOne)
+ putEntry(ctx, t, masterStore, data.AlphaTest, data.AlphaPositiveDigest, expectations.PositiveInt, userOne)
clStore := masterStore.ForChangeList("1687", "gerrit") // this is arbitrary
secondTime := time.Date(2020, time.March, 14, 2, 3, 4, 0, time.UTC)
@@ -847,7 +847,7 @@
defer cleanup()
masterStore := New(c, nil, ReadWrite)
- putEntry(ctx, t, masterStore, data.AlphaTest, data.AlphaPositiveDigest, expectations.Positive, userOne)
+ putEntry(ctx, t, masterStore, data.AlphaTest, data.AlphaPositiveDigest, expectations.PositiveInt, userOne)
_, _, err := masterStore.QueryLog(ctx, -1, 100, false)
require.Error(t, err)
@@ -870,7 +870,7 @@
return fakeNow
}
- putEntry(ctx, t, masterStore, data.AlphaTest, data.AlphaPositiveDigest, expectations.Positive, userOne)
+ putEntry(ctx, t, masterStore, data.AlphaTest, data.AlphaPositiveDigest, expectations.PositiveInt, userOne)
secondTime := time.Date(2020, time.March, 14, 2, 3, 4, 0, time.UTC)
fakeNow = secondTime
@@ -999,9 +999,9 @@
masterStore := New(c, nil, ReadWrite)
require.NoError(t, masterStore.Initialize(ctx))
- putEntry(ctx, t, masterStore, data.AlphaTest, data.AlphaPositiveDigest, expectations.Positive, userOne)
- putEntry(ctx, t, masterStore, data.AlphaTest, data.AlphaPositiveDigest, expectations.Negative, userOne) // will be undone
- putEntry(ctx, t, masterStore, data.AlphaTest, data.AlphaNegativeDigest, expectations.Negative, userOne)
+ putEntry(ctx, t, masterStore, data.AlphaTest, data.AlphaPositiveDigest, expectations.PositiveInt, userOne)
+ putEntry(ctx, t, masterStore, data.AlphaTest, data.AlphaPositiveDigest, expectations.NegativeInt, userOne) // will be undone
+ putEntry(ctx, t, masterStore, data.AlphaTest, data.AlphaNegativeDigest, expectations.NegativeInt, userOne)
entries, _, err := masterStore.QueryLog(ctx, 0, 10, false)
require.NoError(t, err)
@@ -1041,9 +1041,9 @@
masterStore := New(c, nil, ReadWrite)
clStore := masterStore.ForChangeList("123", "github") // These are arbitrary
- putEntry(ctx, t, clStore, data.AlphaTest, data.AlphaPositiveDigest, expectations.Positive, userOne)
- putEntry(ctx, t, clStore, data.AlphaTest, data.AlphaPositiveDigest, expectations.Negative, userOne) // will be undone
- putEntry(ctx, t, clStore, data.AlphaTest, data.AlphaNegativeDigest, expectations.Negative, userOne)
+ putEntry(ctx, t, clStore, data.AlphaTest, data.AlphaPositiveDigest, expectations.PositiveInt, userOne)
+ putEntry(ctx, t, clStore, data.AlphaTest, data.AlphaPositiveDigest, expectations.NegativeInt, userOne) // will be undone
+ putEntry(ctx, t, clStore, data.AlphaTest, data.AlphaNegativeDigest, expectations.NegativeInt, userOne)
entries, _, err := clStore.QueryLog(ctx, 0, 10, false)
require.NoError(t, err)
@@ -1183,12 +1183,12 @@
entryOne, entryTwo, entryThree := populateFirestore(ctx, t, c, updatedLongAgo)
// The time passed here is before all entries
- n, err := masterStore.MarkUnusedEntriesForGC(ctx, expectations.Positive, entryOne.LastUsed.Add(-time.Second))
+ n, err := masterStore.MarkUnusedEntriesForGC(ctx, expectations.PositiveInt, entryOne.LastUsed.Add(-time.Second))
require.NoError(t, err)
assert.Equal(t, 0, n)
// The time passed here is before all negative entries. It is after entryOne (which is positive)
// so we still expect nothing to have changed.
- n, err = masterStore.MarkUnusedEntriesForGC(ctx, expectations.Negative, entryTwo.LastUsed.Add(-time.Second))
+ n, err = masterStore.MarkUnusedEntriesForGC(ctx, expectations.NegativeInt, entryTwo.LastUsed.Add(-time.Second))
require.NoError(t, err)
assert.Equal(t, 0, n)
@@ -1217,7 +1217,7 @@
cutoff := entryThree.LastUsed.Add(-time.Minute)
assert.True(t, cutoff.After(entryOne.LastUsed))
assert.True(t, cutoff.After(entryTwo.LastUsed))
- n, err := masterStore.MarkUnusedEntriesForGC(ctx, expectations.Positive, cutoff)
+ n, err := masterStore.MarkUnusedEntriesForGC(ctx, expectations.PositiveInt, cutoff)
require.NoError(t, err)
assert.Equal(t, 1, n)
@@ -1246,7 +1246,7 @@
cutoff := entryThree.LastUsed.Add(time.Minute)
assert.True(t, cutoff.After(entryOne.LastUsed))
assert.True(t, cutoff.After(entryTwo.LastUsed))
- n, err := masterStore.MarkUnusedEntriesForGC(ctx, expectations.Negative, cutoff)
+ n, err := masterStore.MarkUnusedEntriesForGC(ctx, expectations.NegativeInt, cutoff)
require.NoError(t, err)
assert.Equal(t, 1, n)
@@ -1275,7 +1275,7 @@
cutoff := entryThree.LastUsed.Add(time.Minute)
assert.True(t, cutoff.After(entryOne.LastUsed))
assert.True(t, cutoff.After(entryTwo.LastUsed))
- n, err := masterStore.MarkUnusedEntriesForGC(ctx, expectations.Positive, cutoff)
+ n, err := masterStore.MarkUnusedEntriesForGC(ctx, expectations.PositiveInt, cutoff)
require.NoError(t, err)
assert.Equal(t, 2, n)
@@ -1308,7 +1308,7 @@
cutoff := entryThree.LastUsed.Add(time.Minute)
assert.True(t, cutoff.After(entryOne.LastUsed))
assert.True(t, cutoff.After(entryTwo.LastUsed))
- n, err := masterStore.MarkUnusedEntriesForGC(ctx, expectations.Positive, cutoff)
+ n, err := masterStore.MarkUnusedEntriesForGC(ctx, expectations.PositiveInt, cutoff)
require.NoError(t, err)
// None should be affected because the modified stamp is too new.
assert.Equal(t, 0, n)
@@ -1333,7 +1333,7 @@
masterStore := New(c, nil, ReadWrite)
_, entryTwo, entryThree := populateFirestore(ctx, t, c, updatedLongAgo)
- n, err := masterStore.MarkUnusedEntriesForGC(ctx, expectations.Positive, entryThree.LastUsed.Add(time.Minute))
+ n, err := masterStore.MarkUnusedEntriesForGC(ctx, expectations.PositiveInt, entryThree.LastUsed.Add(time.Minute))
require.NoError(t, err)
assert.Equal(t, 2, n)
n, err = masterStore.GarbageCollect(ctx)
@@ -1396,7 +1396,7 @@
require.NoError(t, err)
cutoff := time.Now().Add(time.Hour)
- n, err := masterStore.MarkUnusedEntriesForGC(ctx, expectations.Positive, cutoff)
+ n, err := masterStore.MarkUnusedEntriesForGC(ctx, expectations.PositiveInt, cutoff)
require.NoError(t, err)
assert.Equal(t, 0, n)
@@ -1408,7 +1408,7 @@
{
FirstIndex: beginningOfTime,
LastIndex: endOfTime,
- Label: expectations.Positive,
+ Label: expectations.PositiveInt,
},
}, actualEntryOne.Ranges)
}
@@ -1448,7 +1448,7 @@
return count
}
-func putEntry(ctx context.Context, t *testing.T, f expectations.Store, name types.TestName, digest types.Digest, label expectations.Label, user string) {
+func putEntry(ctx context.Context, t *testing.T, f expectations.Store, name types.TestName, digest types.Digest, label expectations.LabelInt, user string) {
require.NoError(t, f.AddChange(ctx, []expectations.Delta{
{
Grouping: name,
@@ -1486,7 +1486,7 @@
Grouping: entryOneGrouping,
Digest: entryOneDigest,
Ranges: []triageRange{
- {FirstIndex: beginningOfTime, LastIndex: endOfTime, Label: expectations.Positive},
+ {FirstIndex: beginningOfTime, LastIndex: endOfTime, Label: expectations.PositiveInt},
},
Updated: modified,
LastUsed: entryOneUsed,
@@ -1495,7 +1495,7 @@
Grouping: entryTwoGrouping,
Digest: entryTwoDigest,
Ranges: []triageRange{
- {FirstIndex: beginningOfTime, LastIndex: endOfTime, Label: expectations.Negative},
+ {FirstIndex: beginningOfTime, LastIndex: endOfTime, Label: expectations.NegativeInt},
},
Updated: modified,
LastUsed: entryTwoUsed,
@@ -1504,7 +1504,7 @@
Grouping: entryThreeGrouping,
Digest: entryThreeDigest,
Ranges: []triageRange{
- {FirstIndex: beginningOfTime, LastIndex: endOfTime, Label: expectations.Positive},
+ {FirstIndex: beginningOfTime, LastIndex: endOfTime, Label: expectations.PositiveInt},
},
Updated: modified,
LastUsed: entryThreeUsed,
diff --git a/golden/go/expectations/labels.go b/golden/go/expectations/labels.go
index a376229..38114ec 100644
--- a/golden/go/expectations/labels.go
+++ b/golden/go/expectations/labels.go
@@ -1,18 +1,18 @@
package expectations
-// Label for classifying digests.
-type Label int
+// LabelInt for classifying digests.
+type LabelInt int
const (
- // Untriaged represents a previously unseen digest.
- Untriaged Label = iota // == 0
- // Positive represents a known good digest.
- Positive
- // Negative represents a known bad digest.
- Negative
+ // UntriagedInt represents a previously unseen digest.
+ UntriagedInt LabelInt = iota // == 0
+ // PositiveInt represents a known good digest.
+ PositiveInt
+ // NegativeInt represents a known bad digest.
+ NegativeInt
)
-// LabelStr is the string version of Label. Used e.g. to represent digest classifications in JSON.
+// LabelStr is the string version of LabelInt. Used e.g. to represent digest classifications in JSON.
type LabelStr string
const (
@@ -27,26 +27,26 @@
)
// AllLabelStr is a list of all possible LabelStr values. The index of each element in this list
-// must match its Label value (Untriaged = 0, etc.).
+// must match its LabelInt value (Untriaged = 0, etc.).
var AllLabelStr = []LabelStr{UntriagedStr, PositiveStr, NegativeStr}
-func (l Label) String() LabelStr {
+func (l LabelInt) String() LabelStr {
return AllLabelStr[l]
}
-var labels = map[LabelStr]Label{
- UntriagedStr: Untriaged,
- PositiveStr: Positive,
- NegativeStr: Negative,
+var labels = map[LabelStr]LabelInt{
+ UntriagedStr: UntriagedInt,
+ PositiveStr: PositiveInt,
+ NegativeStr: NegativeInt,
}
-// LabelFromString returns the Label corresponding to the given LabelStr, or Untriaged if there is
+// LabelFromString returns the LabelInt corresponding to the given LabelStr, or Untriaged if there is
// no match.
-func LabelFromString(s LabelStr) Label {
+func LabelFromString(s LabelStr) LabelInt {
if l, ok := labels[s]; ok {
return l
}
- return Untriaged
+ return UntriagedInt
}
// ValidLabelStr returns true if the given LabelStr is valid.
diff --git a/golden/go/expectations/labels_test.go b/golden/go/expectations/labels_test.go
index e4f9ff1..e990950 100644
--- a/golden/go/expectations/labels_test.go
+++ b/golden/go/expectations/labels_test.go
@@ -10,21 +10,21 @@
func TestLabel_String_Success(t *testing.T) {
unittest.SmallTest(t)
- assert.Equal(t, UntriagedStr, Untriaged.String())
- assert.Equal(t, PositiveStr, Positive.String())
- assert.Equal(t, NegativeStr, Negative.String())
+ assert.Equal(t, UntriagedStr, UntriagedInt.String())
+ assert.Equal(t, PositiveStr, PositiveInt.String())
+ assert.Equal(t, NegativeStr, NegativeInt.String())
}
func TestLabelFromString_KnownLabelStr_ReturnsCorrespondingLabel(t *testing.T) {
unittest.SmallTest(t)
- assert.Equal(t, Untriaged, LabelFromString(UntriagedStr))
- assert.Equal(t, Positive, LabelFromString(PositiveStr))
- assert.Equal(t, Negative, LabelFromString(NegativeStr))
+ assert.Equal(t, UntriagedInt, LabelFromString(UntriagedStr))
+ assert.Equal(t, PositiveInt, LabelFromString(PositiveStr))
+ assert.Equal(t, NegativeInt, LabelFromString(NegativeStr))
}
func TestLabelFromString_UnknownLabelStr_ReturnsUntriaged(t *testing.T) {
unittest.SmallTest(t)
- assert.Equal(t, Untriaged, LabelFromString("unknown label"))
+ assert.Equal(t, UntriagedInt, LabelFromString("unknown label"))
}
func TestValidLabel_KnownLabelStr_ReturnsTrue(t *testing.T) {
diff --git a/golden/go/expectations/mocks/GarbageCollector.go b/golden/go/expectations/mocks/GarbageCollector.go
index c81336e..32eb330 100644
--- a/golden/go/expectations/mocks/GarbageCollector.go
+++ b/golden/go/expectations/mocks/GarbageCollector.go
@@ -38,18 +38,18 @@
}
// MarkUnusedEntriesForGC provides a mock function with given fields: _a0, _a1, _a2
-func (_m *GarbageCollector) MarkUnusedEntriesForGC(_a0 context.Context, _a1 expectations.Label, _a2 time.Time) (int, error) {
+func (_m *GarbageCollector) MarkUnusedEntriesForGC(_a0 context.Context, _a1 expectations.LabelInt, _a2 time.Time) (int, error) {
ret := _m.Called(_a0, _a1, _a2)
var r0 int
- if rf, ok := ret.Get(0).(func(context.Context, expectations.Label, time.Time) int); ok {
+ if rf, ok := ret.Get(0).(func(context.Context, expectations.LabelInt, time.Time) int); ok {
r0 = rf(_a0, _a1, _a2)
} else {
r0 = ret.Get(0).(int)
}
var r1 error
- if rf, ok := ret.Get(1).(func(context.Context, expectations.Label, time.Time) error); ok {
+ if rf, ok := ret.Get(1).(func(context.Context, expectations.LabelInt, time.Time) error); ok {
r1 = rf(_a0, _a1, _a2)
} else {
r1 = ret.Error(1)
diff --git a/golden/go/expectations/store.go b/golden/go/expectations/store.go
index 5c26f42..ecca476 100644
--- a/golden/go/expectations/store.go
+++ b/golden/go/expectations/store.go
@@ -59,7 +59,7 @@
// they have a modified ts and a last used ts before the given ts. It returns the number of
// affected entries or an error if there were issues. This bulk operation need not appear in the
// triage log. It does not affect CL expectations.
- MarkUnusedEntriesForGC(context.Context, Label, time.Time) (int, error)
+ MarkUnusedEntriesForGC(context.Context, LabelInt, time.Time) (int, error)
// GarbageCollect removes all entries that have previously been marked for GC. It returns the
// number of affected entries or an error if there were issues. This bulk operation will not