func TestBufferedSub(t *testing.T) { l := events.NewLogger() s := l.Subscribe(events.AllEvents) bs := events.NewBufferedSubscription(s, 10*events.BufferSize) go func() { for i := 0; i < 10*events.BufferSize; i++ { l.Log(events.NodeConnected, fmt.Sprintf("event-%d", i)) if i%30 == 0 { // Give the buffer routine time to pick up the events time.Sleep(20 * time.Millisecond) } } }() recv := 0 for recv < 10*events.BufferSize { evs := bs.Since(recv, nil) for _, ev := range evs { if ev.ID != recv+1 { t.Fatalf("Incorrect ID; %d != %d", ev.ID, recv+1) } recv = ev.ID } } }
func init() { l.AddHandler(logger.LevelWarn, showGuiError) sub := events.Default.Subscribe(^events.EventType(events.ItemStarted | events.ItemCompleted)) eventSub = events.NewBufferedSubscription(sub, 1000) }
func init() { l.AddHandler(logger.LevelWarn, showGuiError) sub := events.Default.Subscribe(events.AllEvents) eventSub = events.NewBufferedSubscription(sub, 1000) }