summaryrefslogtreecommitdiff
path: root/ipc/ipdl/test/cxx/TestNestedLoops.cpp
blob: 0e0ba496dece214f5cfc9ca82e52a51e81b31acf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#include "base/basictypes.h"

#include "nsThreadUtils.h"

#include "TestNestedLoops.h"

#include "IPDLUnitTests.h"      // fail etc.

namespace mozilla {
namespace _ipdltest {

//-----------------------------------------------------------------------------
// parent

TestNestedLoopsParent::TestNestedLoopsParent() : mBreakNestedLoop(false)
{
    MOZ_COUNT_CTOR(TestNestedLoopsParent);
}

TestNestedLoopsParent::~TestNestedLoopsParent()
{
    MOZ_COUNT_DTOR(TestNestedLoopsParent);
}

void
TestNestedLoopsParent::Main()
{
    if (!SendStart())
        fail("sending Start");

    // sigh ... spin for a while to let Nonce arrive
    puts(" (sleeping to wait for nonce ... sorry)");
    PR_Sleep(5000);

    // while waiting for the reply to R, we'll receive Nonce
    if (!CallR())
        fail("calling R");

    Close();
}

bool
TestNestedLoopsParent::RecvNonce()
{
    // if we have an OnMaybeDequeueOne waiting for us (we may not, due
    // to the inherent race condition in this test, then this event
    // must be ordered after it in the queue
    MessageLoop::current()->PostTask(
        NewNonOwningRunnableMethod(this, &TestNestedLoopsParent::BreakNestedLoop));

    // sigh ... spin for a while to let the reply to R arrive
    puts(" (sleeping to wait for reply to R ... sorry)");
    PR_Sleep(5000);

    // sigh ... we have no idea when code might do this
    do {
        if (!NS_ProcessNextEvent(nullptr, false))
            fail("expected at least one pending event");
    } while (!mBreakNestedLoop);

    return true;
}

void
TestNestedLoopsParent::BreakNestedLoop()
{
    mBreakNestedLoop = true;
}

//-----------------------------------------------------------------------------
// child

TestNestedLoopsChild::TestNestedLoopsChild()
{
    MOZ_COUNT_CTOR(TestNestedLoopsChild);
}

TestNestedLoopsChild::~TestNestedLoopsChild()
{
    MOZ_COUNT_DTOR(TestNestedLoopsChild);
}

bool
TestNestedLoopsChild::RecvStart()
{
    if (!SendNonce())
        fail("sending Nonce");
    return true;
}

bool
TestNestedLoopsChild::AnswerR()
{
    return true;
}

} // namespace _ipdltest
} // namespace mozilla