Repository navigation
fix(jirapoll): treat an unparseable lastCheck as unset #9852
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
527843f
c999cae
2fa4335
1216ae9
b3b6024
2ec3341
20982f4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -342,23 +342,74 @@ func TestRunFirstLookOldActivityThenIdle(t *testing.T) { | |
| } | ||
| } | ||
|
|
||
| // A garbage lastCheck keeps its issue active (an editor must not be able to | ||
| // hide an issue by writing garbage). Alone in the active set it fails every | ||
| // cycle at the all-failed guard, which is unchanged. | ||
| func TestRunGarbageLastCheckAloneFailsCycle(t *testing.T) { | ||
| // A garbage lastCheck is treated as unset (#9766): the issue stays active | ||
| // (an editor must not be able to hide an issue by writing garbage), gets | ||
| // one first-poll look that saves a valid lastCheck, and is idle next cycle. | ||
| // Neither warning prints the stored value. The cases cover both ways a | ||
| // stored value can fail: JSON that is not a string, and a string that is | ||
| // not a timestamp. | ||
| func TestRunGarbageLastCheckTreatedAsUnset(t *testing.T) { | ||
|
dhshah13 marked this conversation as resolved.
Resolved
dhshah13 marked this conversation as resolved.
Resolved
|
||
| for _, tc := range []struct { | ||
| name string | ||
| stored string | ||
| }{ | ||
| {name: "a string that is not a time", stored: `"garbage-time"`}, | ||
| {name: "JSON that is not a string", stored: `{"garbage":1}`}, | ||
| {name: "not JSON", stored: `garbage, not JSON`}, | ||
| } { | ||
| t.Run(tc.name, func(t *testing.T) { | ||
| now := time.Now().Truncate(time.Second) | ||
| updated := now.Add(-time.Hour) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. MEDIUM: no test tells "treated as unset" apart from "floored to the window start" for an unparseable lastCheck This test sets Suppose an implementation kept The two behaviours differ only when
So no test pins the semantics described in the comment at lock.go:238-243 and in the ADR amendment. The earlier exact-value thread was fixed by the switch to Suggestion: add a Verified: read code at head (lock.go:238-252, poller.go:547-552, poller_idle_test.go:351-452); grep found no unparseable-value case with updated outside the window at 2ec3341; raised by: DeepSeek
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed, it should go in before merge. This row passes on 2ec3341 and fails when the bad value is floored instead of treated as unset: {name: "JSON but not a time, updated 3 days ago", stored: json.RawMessage(`"yesterday"`), updated: now.Add(-72 * time.Hour).Format(jiraTimeLayout), active: true},
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This row covers the {name: "not JSON, updated 3 days ago", stored: json.RawMessage(`not json`), updated: now.Add(-72 * time.Hour).Format(jiraTimeLayout), active: true}, |
||
| mc := newMockClient() | ||
| mc.searchResult = []jira.Issue{idleTestIssue(1, now.Add(-48*time.Hour), updated)} | ||
| mc.properties["PROJ-1"] = map[string]json.RawMessage{lastCheckPropertyKey("acme", "platform"): json.RawMessage(tc.stored)} | ||
| for n := 2; n <= 4; n++ { | ||
| mc.searchResult = append(mc.searchResult, idleTestIssue(n, now.Add(-48*time.Hour), updated)) | ||
| setLastCheck(mc, fmt.Sprintf("PROJ-%d", n), "acme", "platform", updated) | ||
| } | ||
|
|
||
| logs := captureLog(t) | ||
| if err := idleTestPoller(mc, t).Run(context.Background()); err != nil { | ||
| t.Fatalf("cycle 1: %v", err) | ||
| } | ||
| if lc := storedLastCheckAt(t, mc, "PROJ-1"); !lc.Equal(updated) { | ||
| t.Fatalf("lastCheck after cycle 1 = %v, want the issue's updated %v saved over the garbage", lc, updated) | ||
| } | ||
| for _, want := range []string{ | ||
| "lastCheck not a timestamp, treated as unset: PROJ-1", | ||
| "WARNING: lastCheck for PROJ-1 is not a timestamp; treating as unset", | ||
| } { | ||
| if !strings.Contains(logs.String(), want) { | ||
| t.Errorf("log lacks %q:\n%s", want, logs) | ||
| } | ||
| } | ||
| if strings.Contains(logs.String(), "garbage") { | ||
| t.Errorf("log prints the stored value:\n%s", logs) | ||
| } | ||
|
|
||
| before := mc.listCommentsCalls["PROJ-1"] | ||
| if err := idleTestPoller(mc, t).Run(context.Background()); err != nil { | ||
| t.Fatalf("cycle 2: %v", err) | ||
| } | ||
| if mc.listCommentsCalls["PROJ-1"] != before { | ||
| t.Error("cycle 2 looked at an issue with nothing new") | ||
| } | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| // A cycle whose every selected issue fails ends in an error. Here the one | ||
| // active issue's lastCheck cannot be read. | ||
| func TestRunAllSelectedIssuesFailedFailsCycle(t *testing.T) { | ||
| now := time.Now().Truncate(time.Second) | ||
| mc := newMockClient() | ||
| mc.searchResult = []jira.Issue{idleTestIssue(1, now.Add(-48*time.Hour), now.Add(-time.Hour))} | ||
|
dhshah13 marked this conversation as resolved.
Resolved
|
||
| mc.properties["PROJ-1"] = map[string]json.RawMessage{lastCheckPropertyKey("acme", "platform"): json.RawMessage(`"not-a-time"`)} | ||
| for n := 2; n <= 4; n++ { | ||
| mc.searchResult = append(mc.searchResult, idleTestIssue(n, now.Add(-48*time.Hour), now.Add(-time.Hour))) | ||
| setLastCheck(mc, fmt.Sprintf("PROJ-%d", n), "acme", "platform", now.Add(-time.Hour)) | ||
| } | ||
| mc.propertyGetErr[lastCheckPropertyKey("acme", "platform")] = fmt.Errorf("503 service unavailable") | ||
|
|
||
| p := idleTestPoller(mc, t) | ||
| err := p.Run(context.Background()) | ||
| if err == nil || !strings.Contains(err.Error(), "all 1 selected issues failed to process") { | ||
| t.Fatalf("Run() error = %v, want the all-failed guard for the one garbage issue", err) | ||
| t.Fatalf("Run() error = %v, want the all-failed guard", err) | ||
| } | ||
| if len(p.dispatches) != 0 { | ||
| t.Errorf("dispatched %d, want 0", len(p.dispatches)) | ||
|
|
@@ -386,6 +437,7 @@ func TestFilterLockedActivityDecision(t *testing.T) { | |
| {name: "read fails", readErr: true, updated: now.Add(-time.Hour).Format(jiraTimeLayout), active: true}, | ||
| {name: "not JSON", stored: json.RawMessage(`not json`), updated: now.Add(-time.Hour).Format(jiraTimeLayout), active: true}, | ||
| {name: "JSON but not a time", stored: json.RawMessage(`"yesterday"`), updated: now.Add(-time.Hour).Format(jiraTimeLayout), active: true}, | ||
| {name: "JSON but not a time, updated 3 days ago", stored: json.RawMessage(`"yesterday"`), updated: now.Add(-72 * time.Hour).Format(jiraTimeLayout), active: true}, | ||
| {name: "JSON number", stored: json.RawMessage(`42`), updated: now.Add(-time.Hour).Format(jiraTimeLayout), active: true}, | ||
| {name: "missing", updated: now.Add(-time.Hour).Format(jiraTimeLayout), active: true}, | ||
| {name: "empty", stored: json.RawMessage{}, updated: now.Add(-time.Hour).Format(jiraTimeLayout), active: true}, | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.