MCPcopy Create free account
hub / github.com/astercloud/aster / TestMergeNamed_SourceEOF

Function TestMergeNamed_SourceEOF

pkg/stream/stream_test.go:196–242  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

194}
195
196func TestMergeNamed_SourceEOF(t *testing.T) {
197 r1, w1 := Pipe[string](2)
198 r2, w2 := Pipe[string](2)
199
200 go func() {
201 w1.Send("a", nil)
202 w1.Close()
203 }()
204 go func() {
205 w2.Send("b", nil)
206 w2.Send("c", nil)
207 w2.Close()
208 }()
209
210 merged := MergeNamed(map[string]*Reader[string]{
211 "stream1": r1,
212 "stream2": r2,
213 })
214 defer merged.Close()
215
216 var values []string
217 var eofSources []string
218
219 for {
220 v, err := merged.Recv()
221 if errors.Is(err, io.EOF) {
222 break
223 }
224 if name, ok := GetSourceName(err); ok {
225 eofSources = append(eofSources, name)
226 continue
227 }
228 if err != nil {
229 t.Fatalf("unexpected error: %v", err)
230 }
231 values = append(values, v)
232 }
233
234 if len(values) != 3 {
235 t.Errorf("expected 3 values, got %d: %v", len(values), values)
236 }
237
238 // 至少应该报告一个源 EOF
239 if len(eofSources) == 0 {
240 t.Error("expected at least one source EOF")
241 }
242}
243
244func TestTransform_Basic(t *testing.T) {
245 reader := FromSlice([]int{1, 2, 3, 4, 5})

Callers

nothing calls this directly

Calls 6

MergeNamedFunction · 0.85
GetSourceNameFunction · 0.85
RecvMethod · 0.80
CloseMethod · 0.65
ErrorMethod · 0.65
SendMethod · 0.45

Tested by

no test coverage detected