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)) }