ciscoheat / buddy

Your friendly BDD testing library for Haxe!
MIT License
96 stars 24 forks source link

Race problem on C++ target #94

Open darmie opened 2 years ago

darmie commented 2 years ago

Some it functions aren't executed linearly, they seem to run in parallel. How do I fix? afterEach didn't fix it

Example

it('should emit a removeInitial event', (done) -> {
    g.once('removeInitial', (iips) -> {
        final iip:zenflo.graph.GraphIIP = iips[0];
        iip.from.data.should.be('Foo');
        iip.to.node.should.be('Split');
        iip.to.port.should.be('in');
        done();
    });
    g.removeInitial('Split', 'in');
    trace("should emit a removeInitial event =>" + g.initializers);
});
it('should contain no IIPs', () -> {
    trace("should contain no IIPs =>" + g.initializers.length);
    g.initializers.length.should.be(0);
});

The order at which the output prints are:

should contain no IIPs =>1
should emit a removeInitial event =>[]

Expected outcome:

should emit a removeInitial event =>[]
should contain no IIPs =>1
ciscoheat commented 2 years ago

Hi, I can't give you much information at the moment, a bit busy with other things, but if you are able to debug the SuitesRunner.hx you should be able to see if the tests are added and executed in the correct order, at least.

If we keep our fingers crossed that the library code works, check the scope of the variables so the race condition doesn't occur outside the tests. Where g is defined for example.

If that seems ok, since it tests in general should be independent from each other, you could solve the issue by moving the last test into the first one, basically testing just before done is called, instead of a whole new it clause.