fix: a crawl whose store runs out of time still ends failed
The store keeps FinishTimeout, the final status write and the conga job end get their own 30 s bound and prune its own store-sized bound, so the row no longer stays running with the error lost until RecoverStale; adds the code-only crawl.WithFinishTimeout seam. quick-261104-xae, review WR-03.
This commit is contained in:
@@ -250,6 +250,58 @@ func TestCrawlTimeout(t *testing.T) {
|
||||
env.startCrawl(t, token)
|
||||
}
|
||||
|
||||
// TestCrawlStoreTimeout pins 33-REVIEW-GAPFIX WR-03: a crawl whose
|
||||
// result store runs past its bound (crawl.WithFinishTimeout here, the
|
||||
// 10-minute FinishTimeout in production) ends at once, failed with the
|
||||
// store error and finished_at, on a final write of its own; the job
|
||||
// answers nil and a later Start succeeds.
|
||||
func TestCrawlStoreTimeout(t *testing.T) {
|
||||
env := bootCrawlEnv(t)
|
||||
token := env.admin(t, true)
|
||||
site := newFakeSite()
|
||||
site.sitemap("/a")
|
||||
site.plant(doc{path: "/", title: "Home"}, doc{path: "/a", title: "Page a"})
|
||||
id := env.startCrawl(t, token)
|
||||
|
||||
// The store's first write (SavePages' insert of the pages) waits on
|
||||
// this lock until the row has left running.
|
||||
lock := env.db.Begin()
|
||||
if lock.Error != nil {
|
||||
t.Fatal(lock.Error)
|
||||
}
|
||||
var unlockOnce sync.Once
|
||||
unlock := func() { unlockOnce.Do(func() { _ = lock.Rollback().Error }) }
|
||||
t.Cleanup(unlock)
|
||||
if err := lock.Exec(`LOCK TABLE golem15_seo_crawl_pages IN SHARE MODE`).Error; err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
ctx := crawl.WithFinishTimeout(fetchguard.WithTransport(t.Context(), site), 2*time.Second)
|
||||
done := env.runCrawlAsync(t, ctx, id)
|
||||
deadline := time.Now().Add(20 * time.Second)
|
||||
row := env.crawlRow(t, id)
|
||||
for row.Status == models.CrawlQueued || row.Status == models.CrawlRunning {
|
||||
if time.Now().After(deadline) {
|
||||
unlock()
|
||||
t.Fatalf("the crawl is still %s 20 s after its store bound: %+v", row.Status, row)
|
||||
}
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
row = env.crawlRow(t, id)
|
||||
}
|
||||
unlock()
|
||||
if row.Status != models.CrawlFailed || !strings.Contains(row.Error, "storing the crawl results took longer than 2s") ||
|
||||
strings.Contains(row.Error, "time limit") || row.FinishedAt == nil {
|
||||
t.Fatalf("row after the store timeout = %+v", row)
|
||||
}
|
||||
if err := waitJob(t, done); err != nil {
|
||||
t.Fatalf("the job answered %v", err)
|
||||
}
|
||||
if pages := env.storedPages(t, id); len(pages) != 0 {
|
||||
t.Fatalf("stored pages = %v, want none (the store rolled back)", pages)
|
||||
}
|
||||
env.startCrawl(t, token)
|
||||
}
|
||||
|
||||
// TestCrawlStaleRecovery pins P33-60: a running crawl whose heartbeat is
|
||||
// older than StaleAfter is ended by the next Start (failed with the
|
||||
// no-heartbeat error, or cancelled when its cancel was requested), which
|
||||
|
||||
Reference in New Issue
Block a user