Handling a racing condition between Register and NowPlaying, when the queue is empty

This commit is contained in:
Deluan
2016-03-23 13:51:02 -04:00
parent c87b133071
commit 08192e6d23
5 changed files with 93 additions and 34 deletions
+10 -1
View File
@@ -80,7 +80,7 @@ func TestScrobbler(t *testing.T) {
})
})
Convey("Given a DB with two songs", t, func() {
Convey("Given a DB with three songs", t, func() {
mfRepo.SetData(`[{"Id":"1","Title":"Femme Fatale"},{"Id":"2","Title":"Here She Comes Now"},{"Id":"3","Title":"Lady Godiva's Operation"}]`, 3)
itCtrl.skipped = make(map[string]time.Time)
npRepo.ClearAll()
@@ -104,6 +104,15 @@ func TestScrobbler(t *testing.T) {
})
})
})
Convey("When the NowPlaying for the next song happens before the Scrobble", func() {
scrobbler.NowPlaying(1, "DSub", "2", "deluan")
scrobbler.Register(1, "1", time.Now())
Convey("Then the NowPlaying info is not not changed", func() {
np, _ := npRepo.GetAll()
So(np, ShouldHaveLength, 1)
So(np[0].TrackId, ShouldEqual, "2")
})
})
})
}