metricsAccountant = &fakemetricsaccountant.FakeMetricsAccountant{}
	})

	JustBeforeEach(func() {
		listener = New(conf, messageBus, store, usageTracker, metricsAccountant, clock, logger)
		listener.Start()
	})

	beat := func() {
		messageBus.SubjectCallbacks("dea.heartbeat")[0](&nats.Msg{
			Data: app.Heartbeat(1).ToJSON(),
		})
	}

	It("To subscribe to the dea.heartbeat subject", func() {
		Expect(messageBus.Subscriptions("dea.heartbeat")).To(HaveLen(1))
	})

	It("To subscribe to the dea.advertise subject", func() {
		Expect(messageBus.Subscriptions("dea.advertise")).NotTo(BeNil())
		Expect(messageBus.Subscriptions("dea.advertise")).To(HaveLen(1))
	})

	It("To start tracking store usage", func() {
		Expect(usageTracker.StartTrackingUsageCallCount()).To(Equal(1))
		Expect(usageTracker.MeasureUsageCallCount()).To(Equal(1))
		Expect(metricsAccountant.TrackActualStateListenerStoreUsageFractionCallCount()).To(Equal(1))
		Expect(metricsAccountant.TrackActualStateListenerStoreUsageFractionArgsForCall(0)).To(Equal(0.7))
	})

	It("To save heartbeats on a timer", func() {
		listener = New(conf, messageBus, store, usageTracker, metricsAccountant, timeProvider, logger)
		listener.Start()
		Eventually(func() interface{} {
			return timeProvider.TickerChannelFor(HeartbeatSyncTimer)
		}).ShouldNot(BeZero())
	})

	forceHeartbeatSync := func() {
		//This first message, triggers the iteration we care about in a goroutine
		timeProvider.TickerChannelFor(HeartbeatSyncTimer) <- time.Now()
		//This blocks until the goroutine completes.  yes, it does trigger the next round, but that should be a noop
		timeProvider.TickerChannelFor(HeartbeatSyncTimer) <- time.Now()
	}

	It("should subscribe to the dea.heartbeat subject", func() {
		Ω(messageBus.Subscriptions("dea.heartbeat")).ShouldNot(BeNil())
		Ω(messageBus.Subscriptions("dea.heartbeat")).Should(HaveLen(1))
	})

	It("should subscribe to the dea.advertise subject", func() {
		Ω(messageBus.Subscriptions("dea.advertise")).ShouldNot(BeNil())
		Ω(messageBus.Subscriptions("dea.advertise")).Should(HaveLen(1))
	})

	It("should start tracking store usage", func() {
		Ω(usageTracker.DidStart).Should(BeTrue())
		Ω(metricsAccountant.TrackedActualStateListenerStoreUsageFraction).Should(Equal(0.7))
	})

	It("should save heartbeats on a timer", func() {
		Ω(timeProvider.TickerDurationFor(HeartbeatSyncTimer)).Should(Equal(conf.ListenerHeartbeatSyncInterval()))