// TestSceneBehavior tests the scene behavior. func TestSceneBehavior(t *testing.T) { assert := audit.NewTestingAssertion(t, true) env := cells.NewEnvironment("scene-behavior") defer env.Stop() env.StartCell("broadcast", behaviors.NewBroadcasterBehavior()) env.StartCell("scene", behaviors.NewSceneBehavior()) env.Subscribe("broadcast", "scene") scn := scene.Start() defer scn.Stop() env.EmitNew("broadcast", "foo", "bar", scn) value, err := scn.WaitFlagLimitedAndFetch("foo", 5*time.Second) assert.Nil(err) assert.Equal(value, cells.NewPayload("bar")) env.EmitNew("broadcast", "yadda", 42, nil) value, err = scn.WaitFlagLimitedAndFetch("yadda", 1*time.Second) assert.Nil(value) assert.ErrorMatch(err, `.* waiting for signal "yadda" timed out`) }
// TestBroadcasterBehavior tests the broadcast behavior. func TestBroadcasterBehavior(t *testing.T) { assert := audit.NewTestingAssertion(t, true) env := cells.NewEnvironment("broadcast-behavior") defer env.Stop() env.StartCell("broadcast", behaviors.NewBroadcasterBehavior()) env.StartCell("test-1", behaviors.NewCollectorBehavior(10)) env.StartCell("test-2", behaviors.NewCollectorBehavior(10)) env.Subscribe("broadcast", "test-1", "test-2") env.EmitNew("broadcast", "test", "a", nil) env.EmitNew("broadcast", "test", "b", nil) env.EmitNew("broadcast", "test", "c", nil) time.Sleep(100 * time.Millisecond) collected, err := env.Request("test-1", cells.CollectedTopic, nil, nil, cells.DefaultTimeout) assert.Nil(err) assert.Length(collected, 3) collected, err = env.Request("test-2", cells.CollectedTopic, nil, nil, cells.DefaultTimeout) assert.Nil(err) assert.Length(collected, 3) }