harness-drone/scheduler/queue/canceller_test.go

37 lines
890 B
Go
Raw Normal View History

2019-02-19 23:56:41 +00:00
// Copyright 2019 Drone.IO Inc. All rights reserved.
// Use of this source code is governed by the Drone Non-Commercial License
// that can be found in the LICENSE file.
package queue
import (
"context"
"testing"
"time"
)
var noContext = context.Background()
func TestCollect(t *testing.T) {
c := newCanceller()
c.Cancel(noContext, 1)
c.Cancel(noContext, 2)
c.Cancel(noContext, 3)
c.Cancel(noContext, 4)
c.Cancel(noContext, 5)
c.cancelled[3] = c.cancelled[3].Add(time.Minute * -1)
c.cancelled[4] = time.Now().Add(time.Second * -1)
c.cancelled[5] = time.Now().Add(time.Second * -1)
c.collect()
if got, want := len(c.cancelled), 3; got != want {
t.Errorf("Want 3 cancelled builds in the cache, got %d", got)
}
if _, ok := c.cancelled[4]; ok {
t.Errorf("Expect build id [4] removed")
}
if _, ok := c.cancelled[5]; ok {
t.Errorf("Expect build id [5] removed")
}
}