mirror of
https://github.com/tendermint/tendermint.git
synced 2026-01-05 04:55:18 +00:00
## Description Internalize some libs. This reduces the amount ot public API tendermint is supporting. The moved libraries are mainly ones that are used within Tendermint-core.
48 lines
824 B
Go
48 lines
824 B
Go
package sync_test
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
tmsync "github.com/tendermint/tendermint/internal/libs/sync"
|
|
)
|
|
|
|
func TestWaker(t *testing.T) {
|
|
|
|
// A new waker should block when sleeping.
|
|
waker := tmsync.NewWaker()
|
|
|
|
select {
|
|
case <-waker.Sleep():
|
|
require.Fail(t, "unexpected wakeup")
|
|
default:
|
|
}
|
|
|
|
// Wakeups should not block, and should cause the next sleeper to awaken.
|
|
waker.Wake()
|
|
|
|
select {
|
|
case <-waker.Sleep():
|
|
default:
|
|
require.Fail(t, "expected wakeup, but sleeping instead")
|
|
}
|
|
|
|
// Multiple wakeups should only wake a single sleeper.
|
|
waker.Wake()
|
|
waker.Wake()
|
|
waker.Wake()
|
|
|
|
select {
|
|
case <-waker.Sleep():
|
|
default:
|
|
require.Fail(t, "expected wakeup, but sleeping instead")
|
|
}
|
|
|
|
select {
|
|
case <-waker.Sleep():
|
|
require.Fail(t, "unexpected wakeup")
|
|
default:
|
|
}
|
|
}
|