Skip to content

Commit

Permalink
Merge pull request #79 from alpacahq/fix/bitmex-ut
Browse files Browse the repository at this point in the history
fix bitmexfeeder unit test
  • Loading branch information
rocketbitz authored Jun 18, 2018
2 parents 03d81b5 + f97f66c commit 91b7410
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
2 changes: 1 addition & 1 deletion contrib/bitmexfeeder/bitmexfeeder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func (t *TestSuite) TestNew(c *C) {
ret, err = NewBgWorker(config)
worker = ret.(*BitmexFetcher)
c.Assert(err, IsNil)
c.Assert(len(worker.symbols), Equals, 59)
c.Assert(len(worker.symbols), Equals, 28)

config = getConfig(`{
"query_start": "2017-01-02 00:00"
Expand Down
16 changes: 12 additions & 4 deletions contrib/stream/shelf/shelf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ var _ = Suite(&ShelfTestSuite{})
func (s *ShelfTestSuite) TestShelf(c *C) {
// normal expiration
{
expC := make(chan struct{}, 1)
expired := false
h := NewShelfHandler(func(tbk io.TimeBucketKey, data interface{}) error {
expired = true
expC <- struct{}{}
return nil
})

Expand All @@ -29,15 +31,17 @@ func (s *ShelfTestSuite) TestShelf(c *C) {

shelf.Store(tbk, genColumns(), time.Now().Add(time.Millisecond))

<-time.After(2 * time.Millisecond)
<-expC

c.Assert(expired, Equals, true)
}
// replacement with same deadline, then expiration
{
expC := make(chan struct{}, 1)
expireCount := 0
h := NewShelfHandler(func(tbk io.TimeBucketKey, data interface{}) error {
expireCount++
expC <- struct{}{}
return nil
})

Expand All @@ -53,15 +57,19 @@ func (s *ShelfTestSuite) TestShelf(c *C) {
// replace
shelf.Store(tbk, genColumns(), deadline)

<-time.After(200 * time.Millisecond)
<-expC

c.Assert(expireCount, Equals, 1)
}
// replacement with new deadline, then expiration
{
expC := make(chan struct{}, 2)

expireCount := 0
h := NewShelfHandler(func(tbk io.TimeBucketKey, data interface{}) error {
expireCount++
expC <- struct{}{}

return nil
})

Expand All @@ -77,11 +85,11 @@ func (s *ShelfTestSuite) TestShelf(c *C) {
// replace
shelf.Store(tbk, genColumns(), deadline.Add(100*time.Millisecond))

<-time.After(150 * time.Millisecond)
<-expC

c.Assert(expireCount, Equals, 1)

<-time.After(60 * time.Millisecond)
<-expC

c.Assert(expireCount, Equals, 2)
}
Expand Down

0 comments on commit 91b7410

Please sign in to comment.