Esempio n. 1
0
// TestCleaner create 2 metrics, one old and one new.
// After a single run of the cleanup worker it expects the
// old one to be deleted
func (s *CleanupSuite) TestCleaner(c *gc.C) {
	notify := make(chan string)
	cleanup := metricworker.PatchNotificationChannel(notify)
	defer cleanup()
	client := &mockClient{}
	worker := metricworker.NewCleanup(client)
	defer worker.Kill()
	select {
	case <-notify:
	case <-time.After(coretesting.LongWait):
		c.Fatalf("the cleanup function should have fired by now")
	}
	c.Assert(client.calls, gc.DeepEquals, []string{"CleanupOldMetrics"})
}
Esempio n. 2
0
func (s *MetricManagerSuite) TestRunner(c *gc.C) {
	notify := make(chan string, 2)
	cleanup := metricworker.PatchNotificationChannel(notify)
	defer cleanup()
	client := &mockClient{}
	_, err := metricworker.NewMetricsManager(client)
	c.Assert(err, jc.ErrorIsNil)
	expectedCalls := map[string]bool{}
	for i := 0; i < 2; i++ {
		select {
		case call := <-notify:
			expectedCalls[call] = true
		case <-time.After(coretesting.LongWait):
			c.Logf("we should have received a notification by now")
		}
	}

	c.Check(expectedCalls["senderCalled"], jc.IsTrue)
	c.Check(expectedCalls["cleanupCalled"], jc.IsTrue)
}