Skip to content

Commit

Permalink
Improve error message when failing to calculate subnet uptimes (ava-l…
Browse files Browse the repository at this point in the history
  • Loading branch information
joshua-kim authored Mar 7, 2023
1 parent bb4e910 commit 8747a6a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
8 changes: 4 additions & 4 deletions snow/uptime/locked_calculator.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
)

var (
errNotReady = errors.New("should not be called")
errStillBootstrapping = errors.New("still bootstrapping")

_ LockedCalculator = (*lockedCalculator)(nil)
)
Expand All @@ -40,7 +40,7 @@ func (c *lockedCalculator) CalculateUptime(nodeID ids.NodeID, subnetID ids.ID) (
defer c.lock.RUnlock()

if c.isBootstrapped == nil || !c.isBootstrapped.Get() {
return 0, time.Time{}, errNotReady
return 0, time.Time{}, errStillBootstrapping
}

c.calculatorLock.Lock()
Expand All @@ -54,7 +54,7 @@ func (c *lockedCalculator) CalculateUptimePercent(nodeID ids.NodeID, subnetID id
defer c.lock.RUnlock()

if c.isBootstrapped == nil || !c.isBootstrapped.Get() {
return 0, errNotReady
return 0, errStillBootstrapping
}

c.calculatorLock.Lock()
Expand All @@ -68,7 +68,7 @@ func (c *lockedCalculator) CalculateUptimePercentFrom(nodeID ids.NodeID, subnetI
defer c.lock.RUnlock()

if c.isBootstrapped == nil || !c.isBootstrapped.Get() {
return 0, errNotReady
return 0, errStillBootstrapping
}

c.calculatorLock.Lock()
Expand Down
12 changes: 6 additions & 6 deletions snow/uptime/locked_calculator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,27 +28,27 @@ func TestLockedCalculator(t *testing.T) {
nodeID := ids.GenerateTestNodeID()
subnetID := ids.GenerateTestID()
_, _, err := lc.CalculateUptime(nodeID, subnetID)
require.ErrorIs(err, errNotReady)
require.ErrorIs(err, errStillBootstrapping)

_, err = lc.CalculateUptimePercent(nodeID, subnetID)
require.ErrorIs(err, errNotReady)
require.ErrorIs(err, errStillBootstrapping)

_, err = lc.CalculateUptimePercentFrom(nodeID, subnetID, time.Now())
require.ErrorIs(err, errNotReady)
require.ErrorIs(err, errStillBootstrapping)

var isBootstrapped utils.Atomic[bool]
mockCalc := NewMockCalculator(ctrl)

// Should still error because ctx is not bootstrapped
lc.SetCalculator(&isBootstrapped, &sync.Mutex{}, mockCalc)
_, _, err = lc.CalculateUptime(nodeID, subnetID)
require.ErrorIs(err, errNotReady)
require.ErrorIs(err, errStillBootstrapping)

_, err = lc.CalculateUptimePercent(nodeID, subnetID)
require.ErrorIs(err, errNotReady)
require.ErrorIs(err, errStillBootstrapping)

_, err = lc.CalculateUptimePercentFrom(nodeID, subnetID, time.Now())
require.EqualValues(errNotReady, err)
require.EqualValues(errStillBootstrapping, err)

isBootstrapped.Set(true)

Expand Down

0 comments on commit 8747a6a

Please sign in to comment.