async def test_slot_ticker_second_half_tick(event_bus, event_loop): slot_ticker = SlotTicker( genesis_slot=0, genesis_time=int(time.time()) + 1, seconds_per_slot=2, event_bus=event_bus, ) asyncio.ensure_future(slot_ticker.run(), loop=event_loop) await slot_ticker.events.started.wait() try: first_slot_event = await asyncio.wait_for( event_bus.wait_for(SlotTickEvent), timeout=4, loop=event_loop, ) except asyncio.TimeoutError: assert False, "Slot not ticking" assert not first_slot_event.is_second_tick try: second_slot_event = await asyncio.wait_for( event_bus.wait_for(SlotTickEvent), timeout=4, loop=event_loop, ) except asyncio.TimeoutError: assert False, "No second half tick" assert second_slot_event.slot == first_slot_event.slot assert second_slot_event.is_second_tick await slot_ticker.cancel()
async def test_slot_ticker_ticking(event_bus, event_loop): slot_ticker = SlotTicker( genesis_slot=0, genesis_time=int(time.time()) + 1, seconds_per_slot=1, event_bus=event_bus, ) asyncio.ensure_future(slot_ticker.run(), loop=event_loop) try: slot_tick_event = await asyncio.wait_for( event_bus.wait_for(SlotTickEvent), timeout=2, loop=event_loop) except asyncio.TimeoutError: raise AssertionError("Slot not ticking") assert slot_tick_event.slot > 0 await slot_ticker.cancel()
async def test_slot_ticker_all_ticks(event_bus, event_loop): seconds_per_slot = 3 slot_ticker = SlotTicker( genesis_slot=0, genesis_time=int(time.time()) + seconds_per_slot, seconds_per_slot=seconds_per_slot, event_bus=event_bus, ) asyncio.ensure_future(slot_ticker.run(), loop=event_loop) try: first_slot_event = await asyncio.wait_for( event_bus.wait_for(SlotTickEvent), timeout=seconds_per_slot, loop=event_loop, ) except asyncio.TimeoutError: assert False, "Slot not ticking" assert first_slot_event.tick_type.is_start try: second_slot_event = await asyncio.wait_for( event_bus.wait_for(SlotTickEvent), timeout=seconds_per_slot, loop=event_loop, ) except asyncio.TimeoutError: assert False, "Should have gotten the second tick" assert second_slot_event.slot == first_slot_event.slot assert second_slot_event.tick_type.is_one_third try: third_slot_event = await asyncio.wait_for( event_bus.wait_for(SlotTickEvent), timeout=seconds_per_slot, loop=event_loop, ) except asyncio.TimeoutError: assert False, "Should have gotten the third tick" assert third_slot_event.slot == first_slot_event.slot assert third_slot_event.tick_type.is_two_third await slot_ticker.cancel()