开发者

PHPUnit and multi-processing testing

I am writing a library for doing multi-processing (forking) and would like to test it with PHPUnit.

So far I came up with following scenario:开发者_如何学运维

  • Making the process to be tested to run itself as a forked process - so if something goes wrong, the main process where PHPUnit is running would not stuck forever (I use some kind of time limit, after which the tested child process is killed).
  • In the tested process and any other sub-processes created by it I do log all my actions (performed work, received and sent signals, etc) in a some kind of formatted log, which can be later easy processed
  • After all work is done in the main process, where PHPUnit testing is done, I do read and process the created logs and to my assertions - check if expected actions were performed or not.

Are there any would good/better techniques how to do the testing compared to my scenario?


Take a look at how I'm testing Spork. The key is to call pcntl_wait() before running your assertions.


I recommend that you separate the testing of the forking from the testing of the work done in the forked process(es). For example, say your program processes a directory recursively by spawning a child process for each subdirectory and then processing the files in its own directory itself.

Instead of processing a large directory tree in its entirety and analyzing the resulting output--created only for the tests no less--have tests for processing a file, tests for spawning a child with a directory, a test that directories are detected, etc.

Your tests will become easier as you shrink the size of the system each must test to small units of work. When you get to testing that children are spawned, you could mock out the system call if you place it into its own method.

This covers a lot at a very high level. Ask for specifics if you need more details.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜