From 4a0bc7fe83c4bc24f7a943eb6ebd55b5119c7964 Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Thu, 3 Dec 2026 11:09:48 -0800 Subject: [PATCH] mount/page_writer: count only uploads that park after the test starts waiting (#13352) An earlier test can leave an upload parked on its read that goes on only after the next test has counted it. The count of parked uploads then never grows by the ones the next test parks, and it fails after 5s. Track the parked uploads by goroutine id and wait for new ones instead. Co-authored-by: Claude Opus 5.5 --- .../upload_pipeline_read_wakeup_test.go | 26 ++++++++++++++----- 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/weed/mount/page_writer/upload_pipeline_read_wakeup_test.go b/weed/mount/page_writer/upload_pipeline_read_wakeup_test.go index e86e076ee0..9284c2c9ae 100644 --- a/weed/mount/page_writer/upload_pipeline_read_wakeup_test.go +++ b/weed/mount/page_writer/upload_pipeline_read_wakeup_test.go @@ -11,14 +11,27 @@ import ( const wakeupTestChunkSize = 2 * 1024 * 1024 -// parkedUploads counts the uploads waiting on readerCountCond. The wait keeps -// no state to look at, so the goroutines' stack frames are the witness. -func parkedUploads() int { +// parkedUploads returns the goroutine ids of the uploads waiting on +// readerCountCond. The wait keeps no state to look at, so the goroutines' +// stack frames are the witness. +func parkedUploads() map[string]bool { buf := make([]byte, 1<<20) buf = buf[:runtime.Stack(buf, true)] - parked := 0 + parked := make(map[string]bool) for _, stack := range strings.Split(string(buf), "\n\n") { if strings.Contains(stack, "(*UploadPipeline).moveToSealed") && strings.Contains(stack, "sync.(*Cond).Wait") { + parked[strings.Fields(stack)[1]] = true + } + } + return parked +} + +// parkedSince counts the uploads waiting on readerCountCond that were not +// waiting in before. +func parkedSince(before map[string]bool) int { + parked := 0 + for id := range parkedUploads() { + if !before[id] { parked++ } } @@ -27,7 +40,8 @@ func parkedUploads() int { // parkUploads seals a gated chunk at each index while a read holds them, lets // every upload finish, and returns once each of them waits on the read. -// Uploads that an earlier test left waiting are counted out. +// Uploads that an earlier test left waiting are counted out, even when they +// go on in the meantime. func parkUploads(t *testing.T, up *UploadPipeline, indexes ...LogicChunkIndex) []*gatedChunk { t.Helper() before := parkedUploads() @@ -43,7 +57,7 @@ func parkUploads(t *testing.T, up *UploadPipeline, indexes ...LogicChunkIndex) [ <-c.saved } deadline := time.Now().Add(5 * time.Second) - for parkedUploads() < before+len(indexes) { + for parkedSince(before) < len(indexes) { if time.Now().After(deadline) { t.Fatalf("the %d uploads never waited on the read", len(indexes)) }