MCPcopy Index your code
hub / github.com/chain/Core / TestWaitForBlockSoonWaits

Function TestWaitForBlockSoonWaits

protocol/block_test.go:86–110  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

84}
85
86func TestWaitForBlockSoonWaits(t *testing.T) {
87 // This test is inherently racy. It's possible
88 // that the block creation might run before
89 // the wait's internal test loop finds no block.
90 // In that case, the test will pass, but it will
91 // not have tested anything.
92 //
93 // It's the best we can do.
94
95 c, _ := newTestChain(t, time.Now())
96 makeEmptyBlock(t, c) // height=2
97
98 go func() {
99 time.Sleep(10 * time.Millisecond) // sorry for the slow test 
100 makeEmptyBlock(t, c) // height=3
101 }()
102
103 err := <-c.BlockSoonWaiter(context.Background(), 3)
104 if err != nil {
105 t.Fatal(err)
106 }
107 if g := c.Height(); g != 3 {
108 t.Errorf("height after waiting = %d want 3", g)
109 }
110}
111
112func TestWaitForBlockSoonTimesout(t *testing.T) {
113 c, _ := newTestChain(t, time.Now())

Callers

nothing calls this directly

Calls 4

newTestChainFunction · 0.85
makeEmptyBlockFunction · 0.85
BlockSoonWaiterMethod · 0.80
HeightMethod · 0.65

Tested by

no test coverage detected