dimanche 23 octobre 2016

Testing Haskell code : separating state

I am writing a online game in haskell.. My GameEngine is in statemonad so it is simple to test and we have written properties for it. It's just bliss.

However, server has a list of users which is in MVar. Server.hs There are a lot of threads running around. One game thread, tcp and websocket threads, each client on its own thread etc. All of them talks with Channels.

The problem is with testing some user workflow ; like user joins and quits immediately even before game starts ; user leaves in between of game; user quits the game and so on..

User workflow is coupled with all the threads which are in IO(). I tried writing unit tests on functions by passing channels (prefilled with values). But they looked very fragile. Every time i change the code, its hard to understand why test failed. Its not very bad but i am in search of better way.

How can i test my workflows ? Can i use some other kind of programming abstractions ?

I am open to all kind of suggestions (FRP / free monads : I do not know any of them.. but if they solve the problem i am ready to learn.).

Aucun commentaire:

Enregistrer un commentaire