de40b2cd23
We were currently tracking this metrics as a counter (SUM). The number is good, but conceptually this is more a gauge (LastValue), given it can go down. Thus we switch it by tracking the aggregation numbers directy in the operation tracker.
54 lines
987 B
Go
54 lines
987 B
Go
package optracker
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/ipfs/ipfs-cluster/api"
|
|
"github.com/ipfs/ipfs-cluster/test"
|
|
)
|
|
|
|
func TestOperation(t *testing.T) {
|
|
tim := time.Now().Add(-2 * time.Second)
|
|
op := newOperation(context.Background(), api.PinCid(test.Cid1), OperationUnpin, PhaseQueued, nil)
|
|
if !op.Cid().Equals(test.Cid1) {
|
|
t.Error("bad cid")
|
|
}
|
|
if op.Phase() != PhaseQueued {
|
|
t.Error("bad phase")
|
|
}
|
|
|
|
op.SetError(errors.New("fake error"))
|
|
if op.Error() != "fake error" {
|
|
t.Error("bad error")
|
|
}
|
|
|
|
op.SetPhase(PhaseInProgress)
|
|
if op.Phase() != PhaseInProgress {
|
|
t.Error("bad phase")
|
|
}
|
|
|
|
if op.Type() != OperationUnpin {
|
|
t.Error("bad type")
|
|
}
|
|
|
|
if !op.Timestamp().After(tim) {
|
|
t.Error("bad timestamp")
|
|
}
|
|
|
|
if op.Cancelled() {
|
|
t.Error("should not be cancelled")
|
|
}
|
|
|
|
op.Cancel()
|
|
if !op.Cancelled() {
|
|
t.Error("should be cancelled")
|
|
}
|
|
|
|
if op.ToTrackerStatus() != api.TrackerStatusUnpinning {
|
|
t.Error("should be in unpin error")
|
|
}
|
|
}
|