Esempio n. 1
0
func (app Application) StartMessageGC() {
	messageLifetime := 24 * time.Hour
	db := app.mother.Database()
	messagesRepo := app.mother.MessagesRepo()
	pollingInterval := 1 * time.Hour

	logger := log.New(os.Stdout, "", 0)
	messageGC := postal.NewMessageGC(messageLifetime, db, messagesRepo, pollingInterval, logger)
	messageGC.Run()
}
Esempio n. 2
0
	BeforeEach(func() {
		loggerBuffer = bytes.NewBuffer([]byte{})
		logger := log.New(loggerBuffer, "", 0)

		conn = mocks.NewConnection()
		database = mocks.NewDatabase()
		database.ConnectionCall.Returns.Connection = conn

		repo = mocks.NewMessagesRepo()
		lifetime = 2 * time.Minute
		pollingInterval = 500 * time.Millisecond
		oldMessageID = "that-message"
		newMessageID = "this-message"

		messageGC = postal.NewMessageGC(lifetime, database, repo, pollingInterval, logger)
	})

	Describe("Run", func() {
		It("It calls collect every passed in duration", func() {
			messageGC.Run()

			Eventually(func() int {
				return repo.DeleteBeforeCall.CallCount
			}).Should(BeNumerically(">=", 2))

			call1 := repo.DeleteBeforeCall.InvocationTimes[0]
			call2 := repo.DeleteBeforeCall.InvocationTimes[1]
			Expect(call2).To(BeTemporally(">", call1.Add(pollingInterval-50*time.Millisecond)))
			Expect(call2).To(BeTemporally("<", call1.Add(pollingInterval+50*time.Millisecond)))
		})