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 <noreply@anthropic.com>
This commit is contained in:
Chris LuandClaude Opus 5.5 authored and GitHub committed 2026-12-03 11:09:48 -08:00
1 parent 874bc97814
commit 4a0bc7fe83
1 file changed
+20 -6
@@ -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))
}