MCPcopy Create free account
hub / github.com/ReactiveX/RxGo / testConnectableComposed

Function testConnectableComposed

factory_connectable_test.go:265–300  ·  view source on GitHub ↗
(t *testing.T, obs Observable)

Source from the content-addressed store, hash-verified

263}
264
265func testConnectableComposed(t *testing.T, obs Observable) {
266 obs = obs.Map(func(_ context.Context, i interface{}) (interface{}, error) {
267 return i.(int) + 1, nil
268 }, WithPublishStrategy())
269
270 ctx, cancel := context.WithTimeout(context.Background(), time.Second)
271 defer cancel()
272 eg, _ := errgroup.WithContext(ctx)
273
274 expected := []interface{}{2, 3, 4}
275
276 nbConsumers := 3
277 wg := sync.WaitGroup{}
278 wg.Add(nbConsumers)
279 // Before Connect() is called we create multiple observers
280 // We check all observers receive the same items
281 for i := 0; i < nbConsumers; i++ {
282 eg.Go(func() error {
283 observer := obs.Observe(WithContext(ctx))
284 wg.Done()
285
286 got, err := collect(ctx, observer)
287 if err != nil {
288 return err
289 }
290 if !reflect.DeepEqual(got, expected) {
291 return fmt.Errorf("expected: %v, got: %v", expected, got)
292 }
293 return nil
294 })
295 }
296
297 wg.Wait()
298 obs.Connect(ctx)
299 assert.NoError(t, eg.Wait())
300}
301
302func testConnectableWithoutConnect(t *testing.T, obs Observable) {
303 ctx, cancel := context.WithTimeout(context.Background(), 50*time.Millisecond)

Calls 6

WithPublishStrategyFunction · 0.85
WithContextFunction · 0.85
collectFunction · 0.85
MapMethod · 0.65
ObserveMethod · 0.65
ConnectMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…