Browse Source

p2p/trust: Fix nil pointer error on TrustMetric Copy() (#1819)

pull/1827/head
Ricardo Domingos 7 years ago
committed by Anton Kaliaev
parent
commit
e6abdb8b9d
2 changed files with 11 additions and 2 deletions
  1. +3
    -2
      p2p/trust/metric.go
  2. +8
    -0
      p2p/trust/metric_test.go

+ 3
- 2
p2p/trust/metric.go View File

@ -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,


+ 8
- 0
p2p/trust/metric_test.go View File

@ -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…
Cancel
Save