Merge pull request #885 from sargun/fix-races
This commit is contained in:
@@ -19,7 +19,7 @@ type nodePingController struct {
|
|||||||
|
|
||||||
// "Results"
|
// "Results"
|
||||||
sync.Mutex
|
sync.Mutex
|
||||||
result pingResult
|
result *pingResult
|
||||||
}
|
}
|
||||||
|
|
||||||
type pingResult struct {
|
type pingResult struct {
|
||||||
@@ -88,8 +88,8 @@ func (npc *nodePingController) run(ctx context.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
npc.Lock()
|
npc.Lock()
|
||||||
npc.result = pingResult
|
|
||||||
defer npc.Unlock()
|
defer npc.Unlock()
|
||||||
|
npc.result = &pingResult
|
||||||
span.SetStatus(pingResult.error)
|
span.SetStatus(pingResult.error)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -108,5 +108,7 @@ func (npc *nodePingController) getResult(ctx context.Context) (*pingResult, erro
|
|||||||
case <-npc.firstPingCompleted:
|
case <-npc.firstPingCompleted:
|
||||||
}
|
}
|
||||||
|
|
||||||
return &npc.result, nil
|
npc.Lock()
|
||||||
|
defer npc.Unlock()
|
||||||
|
return npc.result, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ package node
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"strings"
|
"strings"
|
||||||
|
"sync"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -392,6 +393,8 @@ func TestPingAfterStatusUpdate(t *testing.T) {
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
|
testP.maxPingIntervalLock.Lock()
|
||||||
|
defer testP.maxPingIntervalLock.Unlock()
|
||||||
assert.Assert(t, testP.maxPingInterval < maxAllowedInterval, "maximum time between node pings (%v) was greater than the maximum expected interval (%v)", testP.maxPingInterval, maxAllowedInterval)
|
assert.Assert(t, testP.maxPingInterval < maxAllowedInterval, "maximum time between node pings (%v) was greater than the maximum expected interval (%v)", testP.maxPingInterval, maxAllowedInterval)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -728,6 +731,7 @@ type testNodeProviderPing struct {
|
|||||||
testNodeProvider
|
testNodeProvider
|
||||||
customPingFunction func(context.Context) error
|
customPingFunction func(context.Context) error
|
||||||
lastPingTime time.Time
|
lastPingTime time.Time
|
||||||
|
maxPingIntervalLock sync.Mutex
|
||||||
maxPingInterval time.Duration
|
maxPingInterval time.Duration
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -741,6 +745,8 @@ func (tnp *testNodeProviderPing) Ping(ctx context.Context) error {
|
|||||||
tnp.lastPingTime = now
|
tnp.lastPingTime = now
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
tnp.maxPingIntervalLock.Lock()
|
||||||
|
defer tnp.maxPingIntervalLock.Unlock()
|
||||||
if now.Sub(tnp.lastPingTime) > tnp.maxPingInterval {
|
if now.Sub(tnp.lastPingTime) > tnp.maxPingInterval {
|
||||||
tnp.maxPingInterval = now.Sub(tnp.lastPingTime)
|
tnp.maxPingInterval = now.Sub(tnp.lastPingTime)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user