vlad_s has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I have a POE-based asynchronous I/O class that does the following:

I'm trying to find out how to write a test script that would test that my generated events are fired correctly.

Ideally I would like to be able to feed my class line by line and after each line verify that the correct events have been fired.

I have used POE::Test::Helpers in the past, but I fail to see how this class could help me perform this line-by-line feeding trick.

Any ideas will be greatly appreciated.

Replies are listed 'Best First'.
Re: Test scripts for POE
by rcaputo (Chaplain) on Jan 17, 2012 at 13:36 UTC
    • Create a session that will test your class.
    • Use POE::Pipe::OneWay to portably create a one-way pipe.
    • Create an object of the class you want to test as a child of the test session. Give it the pipe's read-only filehandle.
    • The tester session writes one line of data to the pipe's write-only filehandle.
    • The class being tested will either respond with all expected events, or it won't (or it might crash or something else).
      • If the tester session receives all expected events, then the test has passed.
      • If the tester session hasn't received all expected events after a reasonable amount of time has passed, then the test has failed.
    • Was that the last line of test data?
      • Yes: Shut down the test.
      • No: Loop. Write the next line of test data to the pipe's write-only filehandle.
      Thank you Rocco, this approach has worked. I was thinking about using pipes, but discarded the idea as the traditional pipe open function blocks. Thanks for writing POE::Pipe (and the rest of the POE as well, great job!)
Re: Test scripts for POE
by vlad_s (Novice) on Jan 17, 2012 at 12:54 UTC

    My current thinking is to fork a child that would host the ReadWrite session and to modify the class so that events are fired not through POE, but rather written out in stringified manner to STDOUT.

    In that case the testing logic run in the parent process can read those stringified events from STDIN and verify they're correct.

    Or is it too complicated? Perhaps there's an easier way out?