# Coverage for tests/e2e/fuzz/test_fuzz_faith.py : 94%

## 55 statements 51 run 4 missing 0 excluded 0 partial

Hot-keys on this page

r m x p toggle line displays

j k next/prev highlighted chunk

0 (zero) top of page

1 (one) first highlighted chunk

1# -*- coding: utf-8 -*-

2 from __future__ import annotations

3

4# -- stdlib --

5# -- third party --

6 import gevent

7

8# -- own --

9 from ..mock import Environ, EventTap

10 from utils.misc import BatchList

11 from .common import UserInputFuzzingHandler, let_it_go

12

13

14# -- code --

15 class GameEnded(Exception):

16 pass

17

18

19 def wait():

20 gevent.idle(-100)

21 gevent.sleep(0.01)

22 gevent.idle(-100)

23

24

25 class TestFuzzTHBattleFaith(object):

26 def testFuzzTHBattleFaith(self):

27 env = Environ()

28 t = EventTap()

29

30 me = gevent.getcurrent()

31

32 def fail_crash(g):

33 e = Exception('GAME CRASH')

34 e.__cause__ = g.runner.exception

35 gevent.kill(me, e)

36 return g

37

38 s = env.server_core()

39 cl = BatchList([env.client_core() for _ in range(6)])

40 t.tap(s, *cl)

41

42 c1r = BatchList(cl[1:])

43 c = cl[0]

44 names = (

45 'Reimu', 'Marisa', 'Youmu', 'Sakuya',

46 'Satori', 'Koishi', 'Remilia', 'Flandre',

47 )

48 for i, name in zip(cl, names):

49 i.auth.login(name)

50 wait()

51 assert all(cl.auth.uid)

52 c.room.create('Test1', 'THBattleFaith', {})

53 wait()

54 gid = c.game.gid_of(t[c.events.game_joined])

55 c1r.room.join(gid)

56 wait()

57 assert [gid] * 6 == [i.game.gid_of(t[i.events.game_joined]) for i in cl]

58

59 s.events.game_crashed += fail_crash

60 for i in cl:

61 g = t[i.events.game_joined]

62 i.events.game_crashed += fail_crash

63 g.event_observer = UserInputFuzzingHandler(g)

64

65 cl.room.get_ready()

66 wait()

67 assert [gid] * 6 == [i.game.gid_of(t[i.events.game_started]) for i in cl]

68

69 wait()

70

71 def game_ended(g):

72 gevent.kill(me, GameEnded())

73 return g

74

75 s.events.game_ended += game_ended

76

77 [i.game.start_game(t[i.events.game_started]) for i in cl]

78

79 try:

80 let_it_go(*cl)

81 except GameEnded:

82 pass