Skip to content
This repository

Fix Test::SharedFork #64

Closed
schwern opened this Issue September 10, 2010 · 5 comments

2 participants

Michael G. Schwern Tokuhiro Matsuno
Michael G. Schwern
Owner

Test::SharedFork allows you to fork but retain shared information between processes. It does this by various hacks, mostly freezing and restoring objects in a temp directory.

The TB2 way would be to write a handler which stores

  • the parent pid
  • a temp directory

When it sees an event, the handler acts in one of two ways.

If it's in the child process...

  • writes each event to the temp directory with a millisecond timestamp to keep order

If it's in the parent process...

  • checks the temp directory for events, reads and deletes them, and posts them only to history

Here's a rough sketch of the parent process handler.

sub _parent_event {
    my $self = shift;
    my $ec = shift;

    my @events = ...read and delete the events...

    my $history = $ec->history;
    for my $event (@events) {
        $history->accept_event($event, $ec);
    }

    return;
}

In this way, events in children can be communicated back to the parent.

#190 will have to be done before this will work. All state must reside in the history object for this to work.

Michael G. Schwern
Owner

(Pulling in @tokuhirom)

@geistteufel and I have been working on a patch for Test::SharedFork using the technique outlined above which more completely stores the test state. It uses the same basic technique as 0.20 is currently using, but uses event handlers to retrieve and store the TB2::History object rather than wrapping methods. This eliminates a small pile of hacky code in SharedFork and makes it much more reliable. You can see the work here: https://github.com/schwern/test-sharedfork/tree/issue/TB2

We're finishing up making it work with Test::Builder::Tester, which swaps out the test environment, as well as proper subtest support. And I'm likely to make it use the existing SharedFork Store object, though the lexical locking is a problem as the lock must span across subroutines.

I'm leaning towards the idea that this should be in TB2 itself, because not just the History but the EventCoordinator and probably the entire TestState should be shared, just like with threads. EventHandlers can't do that. Fork coordination is probably the biggest reason for test authors needing to monkey with the TB2 internals, and it would be nice if they didn't have to do that.

Michael G. Schwern
Owner

The issue for implementing this inside TB2::TestState is #334

Michael G. Schwern
Owner

A fix using coordinated_forks has been sent upstream. tokuhirom/Test-SharedFork#5

Michael G. Schwern
Owner

@tokuhirom merged the pull request. We still need to release Test::More with the shared forking as an alpha and a new Test::SharedFork, but I just want to close this ticket triumphantly right now so I will!

Michael G. Schwern schwern closed this April 20, 2013
schwernbot schwernbot referenced this issue in Test-More/TB2 March 16, 2014
Closed

Fix Test::SharedFork #106

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.