p2p/trust: Fix nil pointer error on TrustMetric Copy() (#1819)
This commit is contained in:
parent
8412b75b10
commit
e6abdb8b9d
|
@ -256,12 +256,13 @@ func (tm *TrustMetric) SetTicker(ticker MetricTicker) {
|
|||
|
||||
// Copy returns a new trust metric with members containing the same values
|
||||
func (tm *TrustMetric) Copy() *TrustMetric {
|
||||
tm.mtx.Lock()
|
||||
defer tm.mtx.Unlock()
|
||||
if tm == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
tm.mtx.Lock()
|
||||
defer tm.mtx.Unlock()
|
||||
|
||||
return &TrustMetric{
|
||||
proportionalWeight: tm.proportionalWeight,
|
||||
integralWeight: tm.integralWeight,
|
||||
|
|
|
@ -56,6 +56,14 @@ func TestTrustMetricConfig(t *testing.T) {
|
|||
tm.Wait()
|
||||
}
|
||||
|
||||
func TestTrustMetricCopyNilPointer(t *testing.T) {
|
||||
var tm *TrustMetric
|
||||
|
||||
ctm := tm.Copy()
|
||||
|
||||
assert.Nil(t, ctm)
|
||||
}
|
||||
|
||||
// XXX: This test fails non-deterministically
|
||||
func _TestTrustMetricStopPause(t *testing.T) {
|
||||
// The TestTicker will provide manual control over
|
||||
|
|
Loading…
Reference in New Issue