{"record":{"id":"09112132495dfe8c","repo":"apache/beam","slug":"passert-count-v-v-want-v","errorCode":null,"errorMessage":"passert.Count(%v) = %v, want %v","messagePattern":"passert\\.Count\\((.+?)\\) = (.+?), want (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/go/pkg/beam/testing/passert/count.go","lineNumber":67,"sourceCode":"\treturn a + 1\n}\n\nfunc (f *elmCountCombineFn) MergeAccumulators(a, b int) int {\n\treturn a + b\n}\n\nfunc (f *elmCountCombineFn) ExtractOutput(a int) int {\n\treturn a\n}\n\ntype errFn struct {\n\tName  string `json:\"name,omitempty\"`\n\tCount int    `json:\"count,omitempty\"`\n}\n\nfunc (f *errFn) ProcessElement(count int) error {\n\tif f.Count != count {\n\t\treturn errors.Errorf(\"passert.Count(%v) = %v, want %v\", f.Name, count, f.Count)\n\t}\n\treturn nil\n}\n","sourceCodeStart":49,"sourceCodeEnd":71,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/testing/passert/count.go#L49-L71","documentation":"passert.Count asserts that a PCollection of key/count pairs matches expected counts. errFn.ProcessElement fails with 'passert.Count(%v) = %v, want %v' when the observed count for a name differs from the expected count supplied to the assertion.","triggerScenarios":"The assertion DoFn runs over the counted PCollection and an element's actual count != f.Count, i.e. the pipeline produced a different occurrence count for some key than expected.","commonSituations":"Pipeline aggregation logic changed (filters added/removed, dedup changes); expected counts hardcoded against an older dataset; nondeterministic test input.","solutions":["Use the message to identify which key observed which count vs expected; trace the upstream counting transforms.","Update expected counts if the new behavior is intentional.","Fix filtering/deduplication/windowing logic if counts are genuinely wrong.","Make test input deterministic."],"exampleFix":"// before\npassert.Count(s, \"counts\", col, map[string]int{\"a\": 3, \"b\": 2}) // pipeline yields a=4\n// after\npassert.Count(s, \"counts\", col, map[string]int{\"a\": 4, \"b\": 2}) // or fix upstream logic","handlingStrategy":"try-catch","validationCode":"got := map[string]int{}\n// collect counts from a test-side sink before asserting\nif diff := cmp.Diff(want, got); diff != \"\" {\n\tt.Fatalf(\"count mismatch before passert: %v\", diff)\n}","typeGuard":null,"tryCatchPattern":"if err := beamx.Execute(ctx, p); err != nil {\n\tif strings.Contains(err.Error(), \"passert.Count\") {\n\t\t// parse observed vs want from the message and diff upstream logic\n\t}\n\tt.Fatal(err)\n}","preventionTips":["Keep test input deterministic.","Re-derive expected counts whenever aggregation logic changes.","Log intermediate PCollections during test debugging."],"tags":["go","beam","testing","passert"],"backgroundTag":"assertion-failed","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}