Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | #include "TestInterruptShutdownRace.h" |
michael@0 | 2 | |
michael@0 | 3 | #include "IPDLUnitTests.h" // fail etc. |
michael@0 | 4 | #include "IPDLUnitTestSubprocess.h" |
michael@0 | 5 | |
michael@0 | 6 | template<> |
michael@0 | 7 | struct RunnableMethodTraits<mozilla::_ipdltest::TestInterruptShutdownRaceParent> |
michael@0 | 8 | { |
michael@0 | 9 | static void RetainCallee(mozilla::_ipdltest::TestInterruptShutdownRaceParent* obj) { } |
michael@0 | 10 | static void ReleaseCallee(mozilla::_ipdltest::TestInterruptShutdownRaceParent* obj) { } |
michael@0 | 11 | }; |
michael@0 | 12 | |
michael@0 | 13 | |
michael@0 | 14 | namespace mozilla { |
michael@0 | 15 | namespace _ipdltest { |
michael@0 | 16 | |
michael@0 | 17 | //----------------------------------------------------------------------------- |
michael@0 | 18 | // parent |
michael@0 | 19 | |
michael@0 | 20 | namespace { |
michael@0 | 21 | |
michael@0 | 22 | // NB: this test does its own shutdown, rather than going through |
michael@0 | 23 | // QuitParent(), because it's testing degenerate edge cases |
michael@0 | 24 | |
michael@0 | 25 | void DeleteSubprocess() |
michael@0 | 26 | { |
michael@0 | 27 | delete gSubprocess; |
michael@0 | 28 | gSubprocess = nullptr; |
michael@0 | 29 | } |
michael@0 | 30 | |
michael@0 | 31 | void Done() |
michael@0 | 32 | { |
michael@0 | 33 | passed(__FILE__); |
michael@0 | 34 | QuitParent(); |
michael@0 | 35 | } |
michael@0 | 36 | |
michael@0 | 37 | } // namespace <anon> |
michael@0 | 38 | |
michael@0 | 39 | TestInterruptShutdownRaceParent::TestInterruptShutdownRaceParent() |
michael@0 | 40 | { |
michael@0 | 41 | MOZ_COUNT_CTOR(TestInterruptShutdownRaceParent); |
michael@0 | 42 | } |
michael@0 | 43 | |
michael@0 | 44 | TestInterruptShutdownRaceParent::~TestInterruptShutdownRaceParent() |
michael@0 | 45 | { |
michael@0 | 46 | MOZ_COUNT_DTOR(TestInterruptShutdownRaceParent); |
michael@0 | 47 | } |
michael@0 | 48 | |
michael@0 | 49 | void |
michael@0 | 50 | TestInterruptShutdownRaceParent::Main() |
michael@0 | 51 | { |
michael@0 | 52 | if (!SendStart()) |
michael@0 | 53 | fail("sending Start"); |
michael@0 | 54 | } |
michael@0 | 55 | |
michael@0 | 56 | bool |
michael@0 | 57 | TestInterruptShutdownRaceParent::RecvStartDeath() |
michael@0 | 58 | { |
michael@0 | 59 | // this will be ordered before the OnMaybeDequeueOne event of |
michael@0 | 60 | // Orphan in the queue |
michael@0 | 61 | MessageLoop::current()->PostTask( |
michael@0 | 62 | FROM_HERE, |
michael@0 | 63 | NewRunnableMethod(this, |
michael@0 | 64 | &TestInterruptShutdownRaceParent::StartShuttingDown)); |
michael@0 | 65 | return true; |
michael@0 | 66 | } |
michael@0 | 67 | |
michael@0 | 68 | void |
michael@0 | 69 | TestInterruptShutdownRaceParent::StartShuttingDown() |
michael@0 | 70 | { |
michael@0 | 71 | // NB: we sleep here to try and avoid receiving the Orphan message |
michael@0 | 72 | // while waiting for the CallExit() reply. if we fail at that, it |
michael@0 | 73 | // will cause the test to pass spuriously, because there won't be |
michael@0 | 74 | // an OnMaybeDequeueOne task for Orphan |
michael@0 | 75 | PR_Sleep(2000); |
michael@0 | 76 | |
michael@0 | 77 | if (CallExit()) |
michael@0 | 78 | fail("connection was supposed to be interrupted"); |
michael@0 | 79 | |
michael@0 | 80 | Close(); |
michael@0 | 81 | |
michael@0 | 82 | delete static_cast<TestInterruptShutdownRaceParent*>(gParentActor); |
michael@0 | 83 | gParentActor = nullptr; |
michael@0 | 84 | |
michael@0 | 85 | XRE_GetIOMessageLoop()->PostTask(FROM_HERE, |
michael@0 | 86 | NewRunnableFunction(DeleteSubprocess)); |
michael@0 | 87 | |
michael@0 | 88 | // this is ordered after the OnMaybeDequeueOne event in the queue |
michael@0 | 89 | MessageLoop::current()->PostTask(FROM_HERE, |
michael@0 | 90 | NewRunnableFunction(Done)); |
michael@0 | 91 | |
michael@0 | 92 | // |this| has been deleted, be mindful |
michael@0 | 93 | } |
michael@0 | 94 | |
michael@0 | 95 | bool |
michael@0 | 96 | TestInterruptShutdownRaceParent::RecvOrphan() |
michael@0 | 97 | { |
michael@0 | 98 | // it would be nice to fail() here, but we'll process this message |
michael@0 | 99 | // while waiting for the reply CallExit(). The OnMaybeDequeueOne |
michael@0 | 100 | // task will still be in the queue, it just wouldn't have had any |
michael@0 | 101 | // work to do, if we hadn't deleted ourself |
michael@0 | 102 | return true; |
michael@0 | 103 | } |
michael@0 | 104 | |
michael@0 | 105 | //----------------------------------------------------------------------------- |
michael@0 | 106 | // child |
michael@0 | 107 | |
michael@0 | 108 | TestInterruptShutdownRaceChild::TestInterruptShutdownRaceChild() |
michael@0 | 109 | { |
michael@0 | 110 | MOZ_COUNT_CTOR(TestInterruptShutdownRaceChild); |
michael@0 | 111 | } |
michael@0 | 112 | |
michael@0 | 113 | TestInterruptShutdownRaceChild::~TestInterruptShutdownRaceChild() |
michael@0 | 114 | { |
michael@0 | 115 | MOZ_COUNT_DTOR(TestInterruptShutdownRaceChild); |
michael@0 | 116 | } |
michael@0 | 117 | |
michael@0 | 118 | bool |
michael@0 | 119 | TestInterruptShutdownRaceChild::RecvStart() |
michael@0 | 120 | { |
michael@0 | 121 | if (!SendStartDeath()) |
michael@0 | 122 | fail("sending StartDeath"); |
michael@0 | 123 | |
michael@0 | 124 | // See comment in StartShuttingDown(): we want to send Orphan() |
michael@0 | 125 | // while the parent is in its PR_Sleep() |
michael@0 | 126 | PR_Sleep(1000); |
michael@0 | 127 | |
michael@0 | 128 | if (!SendOrphan()) |
michael@0 | 129 | fail("sending Orphan"); |
michael@0 | 130 | |
michael@0 | 131 | return true; |
michael@0 | 132 | } |
michael@0 | 133 | |
michael@0 | 134 | bool |
michael@0 | 135 | TestInterruptShutdownRaceChild::AnswerExit() |
michael@0 | 136 | { |
michael@0 | 137 | _exit(0); |
michael@0 | 138 | NS_RUNTIMEABORT("unreached"); |
michael@0 | 139 | return false; |
michael@0 | 140 | } |
michael@0 | 141 | |
michael@0 | 142 | |
michael@0 | 143 | } // namespace _ipdltest |
michael@0 | 144 | } // namespace mozilla |