mirror of
https://github.com/tendermint/tendermint.git
synced 2026-09-20 15:04:22 +00:00
fastsync/rpc: add TotalSyncedTime & RemainingTime to SyncInfo in /status RPC (#6620)
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
package sync
|
||||
|
||||
import "sync/atomic"
|
||||
|
||||
// AtomicBool is an atomic Boolean.
|
||||
// Its methods are all atomic, thus safe to be called by multiple goroutines simultaneously.
|
||||
// Note: When embedding into a struct one should always use *AtomicBool to avoid copy.
|
||||
// it's a simple implmentation from https://github.com/tevino/abool
|
||||
type AtomicBool int32
|
||||
|
||||
// NewBool creates an AtomicBool with given default value.
|
||||
func NewBool(ok bool) *AtomicBool {
|
||||
ab := new(AtomicBool)
|
||||
if ok {
|
||||
ab.Set()
|
||||
}
|
||||
return ab
|
||||
}
|
||||
|
||||
// Set sets the Boolean to true.
|
||||
func (ab *AtomicBool) Set() {
|
||||
atomic.StoreInt32((*int32)(ab), 1)
|
||||
}
|
||||
|
||||
// UnSet sets the Boolean to false.
|
||||
func (ab *AtomicBool) UnSet() {
|
||||
atomic.StoreInt32((*int32)(ab), 0)
|
||||
}
|
||||
|
||||
// IsSet returns whether the Boolean is true.
|
||||
func (ab *AtomicBool) IsSet() bool {
|
||||
return atomic.LoadInt32((*int32)(ab))&1 == 1
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package sync
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestDefaultValue(t *testing.T) {
|
||||
t.Parallel()
|
||||
v := NewBool(false)
|
||||
assert.False(t, v.IsSet())
|
||||
|
||||
v = NewBool(true)
|
||||
assert.True(t, v.IsSet())
|
||||
}
|
||||
|
||||
func TestSetUnSet(t *testing.T) {
|
||||
t.Parallel()
|
||||
v := NewBool(false)
|
||||
|
||||
v.Set()
|
||||
assert.True(t, v.IsSet())
|
||||
|
||||
v.UnSet()
|
||||
assert.False(t, v.IsSet())
|
||||
}
|
||||
Reference in New Issue
Block a user