func TestPubSubBubbling(t *testing.T) { defer errLogBuf.Reset() testPath := "a/b/c" m := config.NewManager() _, err := m.Subscribe("", nil) assert.EqualError(t, err, config.ErrPathEmpty.Error()) subID, err := m.Subscribe(testPath, &testSubscriber{ f: func(path string, sg scope.Scope, id int64) error { assert.Equal(t, testPath, path) if sg == scope.DefaultID { assert.Equal(t, int64(0), id) } else { assert.Equal(t, int64(123), id) } return nil }, }) assert.NoError(t, err) assert.Equal(t, 1, subID, "The very first subscription ID should be 1") assert.NoError(t, m.Write(config.Value(1), config.Path(testPath), config.Scope(scope.WebsiteID, 123))) assert.NoError(t, m.Close()) time.Sleep(time.Millisecond * 10) // wait for goroutine to close // send on closed channel assert.NoError(t, m.Write(config.Value(1), config.Path(testPath+"Doh"), config.Scope(scope.WebsiteID, 3))) assert.EqualError(t, m.Close(), config.ErrPublisherClosed.Error()) }
func TestPubSubBubbling(t *testing.T) { defer debugLogBuf.Reset() testPath := "a/b/c" s := config.NewService() _, err := s.Subscribe("", nil) assert.EqualError(t, err, config.ErrPathEmpty.Error()) subID, err := s.Subscribe(testPath, &testSubscriber{ f: func(path string, sg scope.Scope, id int64) error { assert.Equal(t, testPath, path) if sg == scope.DefaultID { assert.Equal(t, int64(0), id) } else { assert.Equal(t, int64(123), id) } return nil }, }) assert.NoError(t, err) assert.Equal(t, 1, subID, "The very first subscription ID should be 1") assert.NoError(t, s.Write(config.Value(1), config.Path(testPath), config.Scope(scope.WebsiteID, 123))) assert.NoError(t, s.Close()) // send on closed channel assert.NoError(t, s.Write(config.Value(1), config.Path(testPath+"Doh"), config.Scope(scope.WebsiteID, 3))) assert.EqualError(t, s.Close(), config.ErrPublisherClosed.Error()) }