feat(mobile): переживание сна и рестарта на Android
This commit is contained in:
1 parent
0a6b0e0e85
commit
681dde8a6d
29 files changed
+1253
-93
No files matched your search
@@ -0,0 +1,52 @@
|
||||
package wake
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestFireWakesAllListeners(t *testing.T) {
|
||||
n := New()
|
||||
a, b := n.Chan(), n.Chan()
|
||||
n.Fire()
|
||||
|
||||
for i, ch := range []<-chan struct{}{a, b} {
|
||||
select {
|
||||
case <-ch:
|
||||
case <-time.After(time.Second):
|
||||
t.Fatalf("listener %d did not wake", i)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Канал одноразовый: взятый после Fire ждёт следующего.
|
||||
func TestChanIsRenewedAfterFire(t *testing.T) {
|
||||
n := New()
|
||||
n.Fire()
|
||||
|
||||
next := n.Chan()
|
||||
select {
|
||||
case <-next:
|
||||
t.Fatal("fresh channel is already closed")
|
||||
default:
|
||||
}
|
||||
|
||||
n.Fire()
|
||||
select {
|
||||
case <-next:
|
||||
case <-time.After(time.Second):
|
||||
t.Fatal("second Fire did not reach the fresh channel")
|
||||
}
|
||||
}
|
||||
|
||||
// Нулевой Notifier даёт nil-канал: вызывающему не нужен случай "сигнала нет".
|
||||
func TestNilNotifierBlocksForever(t *testing.T) {
|
||||
var n *Notifier
|
||||
n.Fire()
|
||||
|
||||
select {
|
||||
case <-n.Chan():
|
||||
t.Fatal("nil notifier produced a ready channel")
|
||||
case <-time.After(10 * time.Millisecond):
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user