2021-07-13 15:58:47 +00:00
|
|
|
package metric
|
|
|
|
|
|
|
|
import (
|
2022-05-05 05:56:28 +00:00
|
|
|
"context"
|
2021-07-13 15:58:47 +00:00
|
|
|
"testing"
|
2022-05-05 05:56:28 +00:00
|
|
|
"time"
|
2021-07-13 15:58:47 +00:00
|
|
|
|
2022-05-05 05:56:28 +00:00
|
|
|
"github.com/golang-queue/queue"
|
2021-07-13 15:58:47 +00:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
2022-05-05 05:56:28 +00:00
|
|
|
var noTask = func(ctx context.Context) error { return nil }
|
2021-07-13 15:58:47 +00:00
|
|
|
|
2022-05-05 05:56:28 +00:00
|
|
|
func TestNewMetrics(t *testing.T) {
|
|
|
|
q := queue.NewPool(10)
|
|
|
|
assert.NoError(t, q.QueueTask(noTask))
|
|
|
|
assert.NoError(t, q.QueueTask(noTask))
|
|
|
|
time.Sleep(10 * time.Millisecond)
|
|
|
|
defer q.Release()
|
|
|
|
m := NewMetrics(q)
|
|
|
|
assert.Equal(t, 2, m.q.SubmittedTasks())
|
|
|
|
assert.Equal(t, 2, m.q.SuccessTasks())
|
2021-07-13 15:58:47 +00:00
|
|
|
}
|