Closed hgducharme closed 1 year ago
I don't know if I'll exactly have EventStreamWatcher
handling the challenge request. This is the issue currently attached to the branch I'm working on (which has basically just turned into getting a working test suite for EventStreamWatcher
).
The current issue with getting the test suite working is:
1) EventStreamWatcher
receives a gameStart
event
2) EventStreamWatcher
tells GameManager
to create a new game
3) GameManager
creates a new ChessGame
thread and starts the thread
4) ContinuousWorker.run()
gets invoked which invokes ChessGame.work()
5) The issue is inside ChessGame.work()
where it makes a call to the API and requests the game stream, but we haven't mocked that call
Does it make sense in the Test_EventStreamManager
file to mock out that call? I suppose so
Current issue: need to mock out ChessGame
API call. Mocking it inside the event_stream_manager
fixture inside test_EventStreamManager.py
is not working
TODO: On test teardown, end all non-daemon threads like instances of ChessGame
Current issue: need to mock out
ChessGame
API call. Mocking it inside theevent_stream_manager
fixture insidetest_EventStreamManager.py
is not working
I'm thinking of going back to using a combination of requests
and mocks (per issue #19). I have a feeling I need to mock out ChessGame
or a ChessGameFactory
. The issue i'm running into right now is this:
I'm trying to test that on a gameStart
event, the EventStreamWatcher
properly dispatches it and ultimately all we need to test is that a ChessGame
instance gets created in our system. The ChessGame
instance gets created but because it's a separate thread I'm running into an issue where the EventStreamWatcher
test thread is ending before ChessGame
makes its API call, and therefore the API call isn't being mocked. The solution to this: start tearing down the chess thread, and in the middle, check that it exists in the GameManager.games
dictionary, and then finish the teardown. Another solution is to do time.sleep()
to give the ChessGame
enough time to but that seems like a horrendous way to handle the issue.
Right now the ChessGame
is actively trying to query the engine for the right move and what not, and this is just completely unnecessary for a test regarding EventStreamWatcher
. The only things we are concerned about are
gameStart
event produces a ChessGame
instancegameFinish
event gets rid of the ChessGame
instancechallenge
event gets accepted if we're accepting games, and declined if we're notchallengeDeclined
event does not produce a ChessGame
instance or anything like thatSo I think I need to mock ChessGame
so that it's not querying the Engine
and actually trying to do its own business logic, because we don't care about that when testing EventStreamWatcher
A test suite is really highlighting all the poorly written things in the code base...
In order to complete this we need to do #14, so i'll jump to fixing that first
Technically the lichess api offers a challenge stream for viewing incoming and outgoing challenges but these challenges also appear in the event stream, and it's probably simpler to just have one thread reading in all the events, and dispatching the appropriate action