Bug 1731564: Use motivated SpinEventLoopUntil inside netwerk/*. r=necko-reviewers,valentin

Depends on D127102

Differential Revision: https://phabricator.services.mozilla.com/D127225
This commit is contained in:
Jens Stutte 2021-10-06 19:45:14 +00:00
Родитель 4c843c7054
Коммит b3a8e550fe
11 изменённых файлов: 94 добавлений и 41 удалений

Просмотреть файл

@ -471,7 +471,7 @@ bool ProxyAutoConfig::ResolveAddress(const nsCString& aHostName,
// Spin the event loop of the pac thread until lookup is complete.
// nsPACman is responsible for keeping a queue and only allowing
// one PAC execution at a time even when it is called re-entrantly.
SpinEventLoopUntil([&, helper, this]() {
SpinEventLoopUntil("ProxyAutoConfig::ResolveAddress"_ns, [&, helper, this]() {
if (!helper->mRequest) {
return true;
}

Просмотреть файл

@ -85,7 +85,8 @@ nsresult nsAsyncRedirectVerifyHelper::Init(
NS_ENSURE_SUCCESS(rv, rv);
if (synchronize) {
if (!SpinEventLoopUntil([&]() { return !mWaitingForRedirectCallback; })) {
if (!SpinEventLoopUntil("nsAsyncRedirectVerifyHelper::Init"_ns,
[&]() { return !mWaitingForRedirectCallback; })) {
return NS_ERROR_UNEXPECTED;
}
}

Просмотреть файл

@ -31,7 +31,8 @@ already_AddRefed<nsISyncStreamListener> nsSyncStreamListener::Create() {
nsresult nsSyncStreamListener::WaitForData() {
mKeepWaiting = true;
if (!mozilla::SpinEventLoopUntil([&]() { return !mKeepWaiting; })) {
if (!mozilla::SpinEventLoopUntil("nsSyncStreamListener::Create"_ns,
[&]() { return !mKeepWaiting; })) {
return NS_ERROR_FAILURE;
}

Просмотреть файл

@ -156,7 +156,8 @@ nsresult nsHttpConnectionMgr::Shutdown() {
}
// wait for shutdown event to complete
SpinEventLoopUntil([&, shutdownWrapper]() { return shutdownWrapper->mBool; });
SpinEventLoopUntil("nsHttpConnectionMgr::Shutdown"_ns,
[&, shutdownWrapper]() { return shutdownWrapper->mBool; });
return NS_OK;
}

Просмотреть файл

@ -231,21 +231,24 @@ static int FuzzingRunNetworkHttp(const uint8_t* data, size_t size) {
NS_NewRunnableFunction("Dummy", [&]() { mainPingBack = true; }));
}));
SpinEventLoopUntil([&]() -> bool { return mainPingBack; });
SpinEventLoopUntil("FuzzingRunNetworkHttp(mainPingBack)"_ns,
[&]() -> bool { return mainPingBack; });
channelRef = do_GetWeakReference(gHttpChannel);
}
// Wait for the channel to be destroyed
SpinEventLoopUntil([&]() -> bool {
nsCycleCollector_collect(nullptr);
nsCOMPtr<nsIHttpChannel> channel = do_QueryReferent(channelRef);
return channel == nullptr;
});
SpinEventLoopUntil(
"FuzzingRunNetworkHttp(channel == nullptr)"_ns, [&]() -> bool {
nsCycleCollector_collect(nullptr);
nsCOMPtr<nsIHttpChannel> channel = do_QueryReferent(channelRef);
return channel == nullptr;
});
if (!signalNetworkFuzzingDone()) {
// Wait for the connection to indicate closed
SpinEventLoopUntil([&]() -> bool { return gFuzzingConnClosed; });
SpinEventLoopUntil("FuzzingRunNetworkHttp(gFuzzingConnClosed)"_ns,
[&]() -> bool { return gFuzzingConnClosed; });
}
rcsvc->RemoveRequestContext(rcID);

Просмотреть файл

@ -32,15 +32,18 @@ class FuzzingWebSocketListener final : public nsIWebSocketListener {
FuzzingWebSocketListener() = default;
void waitUntilDoneOrStarted() {
SpinEventLoopUntil([&]() { return mChannelDone || mChannelStarted; });
SpinEventLoopUntil("FuzzingWebSocketListener::waitUntilDoneOrStarted"_ns,
[&]() { return mChannelDone || mChannelStarted; });
}
void waitUntilDone() {
SpinEventLoopUntil([&]() { return mChannelDone; });
SpinEventLoopUntil("FuzzingWebSocketListener::waitUntilDone"_ns,
[&]() { return mChannelDone; });
}
void waitUntilDoneOrAck() {
SpinEventLoopUntil([&]() { return mChannelDone || mChannelAck; });
SpinEventLoopUntil("FuzzingWebSocketListener::waitUntilDoneOrAck"_ns,
[&]() { return mChannelDone || mChannelAck; });
}
bool isStarted() { return mChannelStarted; }
@ -200,15 +203,17 @@ static int FuzzingRunNetworkWebsocket(const uint8_t* data, size_t size) {
}
// Wait for the channel to be destroyed
SpinEventLoopUntil([&]() -> bool {
nsCycleCollector_collect(nullptr);
nsCOMPtr<nsIWebSocketChannel> channel = do_QueryReferent(channelRef);
return channel == nullptr;
});
SpinEventLoopUntil(
"FuzzingRunNetworkWebsocket(channel == nullptr)"_ns, [&]() -> bool {
nsCycleCollector_collect(nullptr);
nsCOMPtr<nsIWebSocketChannel> channel = do_QueryReferent(channelRef);
return channel == nullptr;
});
if (!signalNetworkFuzzingDone()) {
// Wait for the connection to indicate closed
SpinEventLoopUntil([&]() -> bool { return gFuzzingConnClosed; });
SpinEventLoopUntil("FuzzingRunNetworkWebsocket(gFuzzingConnClosed)"_ns,
[&]() -> bool { return gFuzzingConnClosed; });
}
return 0;

Просмотреть файл

@ -89,7 +89,9 @@ TEST(TestBufferedInputStream, AsyncWait_async)
ASSERT_FALSE(cb->Called());
// Eventually it is called.
MOZ_ALWAYS_TRUE(mozilla::SpinEventLoopUntil([&]() { return cb->Called(); }));
MOZ_ALWAYS_TRUE(mozilla::SpinEventLoopUntil(
"TEST(TestBufferedInputStream, AsyncWait_async)"_ns,
[&]() { return cb->Called(); }));
ASSERT_TRUE(cb->Called());
}
@ -132,7 +134,9 @@ TEST(TestBufferedInputStream, AsyncWait_async_closureOnly)
ASSERT_FALSE(cb->Called());
// Eventually it is called.
MOZ_ALWAYS_TRUE(mozilla::SpinEventLoopUntil([&]() { return cb->Called(); }));
MOZ_ALWAYS_TRUE(mozilla::SpinEventLoopUntil(
"TEST(TestBufferedInputStream, AsyncWait_async_closureOnly)"_ns,
[&]() { return cb->Called(); }));
ASSERT_TRUE(cb->Called());
}
@ -147,14 +151,18 @@ TEST(TestBufferedInputStream, AsyncWait_after_close)
auto cb = mozilla::MakeRefPtr<testing::InputStreamCallback>();
ASSERT_EQ(NS_OK, bis->AsyncWait(cb, 0, 0, eventTarget));
MOZ_ALWAYS_TRUE(mozilla::SpinEventLoopUntil([&]() { return cb->Called(); }));
MOZ_ALWAYS_TRUE(mozilla::SpinEventLoopUntil(
"TEST(TestBufferedInputStream, AsyncWait_after_close) 1"_ns,
[&]() { return cb->Called(); }));
ASSERT_TRUE(cb->Called());
ASSERT_EQ(NS_OK, bis->Close());
cb = mozilla::MakeRefPtr<testing::InputStreamCallback>();
ASSERT_EQ(NS_OK, bis->AsyncWait(cb, 0, 0, eventTarget));
MOZ_ALWAYS_TRUE(mozilla::SpinEventLoopUntil([&]() { return cb->Called(); }));
MOZ_ALWAYS_TRUE(mozilla::SpinEventLoopUntil(
"TEST(TestBufferedInputStream, AsyncWait_after_close) 2"_ns,
[&]() { return cb->Called(); }));
ASSERT_TRUE(cb->Called());
}
@ -169,7 +177,9 @@ TEST(TestBufferedInputStream, AsyncLengthWait_after_close)
auto cb = mozilla::MakeRefPtr<testing::LengthCallback>();
ASSERT_EQ(NS_OK, bis->AsyncLengthWait(cb, eventTarget));
MOZ_ALWAYS_TRUE(mozilla::SpinEventLoopUntil([&]() { return cb->Called(); }));
MOZ_ALWAYS_TRUE(mozilla::SpinEventLoopUntil(
"TEST(TestBufferedInputStream, AsyncLengthWait_after_close) 1"_ns,
[&]() { return cb->Called(); }));
ASSERT_TRUE(cb->Called());
uint64_t length;
@ -178,6 +188,8 @@ TEST(TestBufferedInputStream, AsyncLengthWait_after_close)
cb = mozilla::MakeRefPtr<testing::LengthCallback>();
ASSERT_EQ(NS_OK, bis->AsyncLengthWait(cb, eventTarget));
MOZ_ALWAYS_TRUE(mozilla::SpinEventLoopUntil([&]() { return cb->Called(); }));
MOZ_ALWAYS_TRUE(mozilla::SpinEventLoopUntil(
"TEST(TestBufferedInputStream, AsyncLengthWait_after_close) 2"_ns,
[&]() { return cb->Called(); }));
ASSERT_TRUE(cb->Called());
}

Просмотреть файл

@ -21,7 +21,8 @@ class WaitForCondition final : public nsIRunnable {
MOZ_ASSERT(mPending == 0);
mPending = pending;
mozilla::SpinEventLoopUntil([&]() { return !mPending; });
mozilla::SpinEventLoopUntil("TestCommon.h:WaitForCondition::Wait"_ns,
[&]() { return !mPending; });
NS_ProcessPendingEvents(nullptr);
}

Просмотреть файл

@ -127,5 +127,6 @@ TEST(TestHttpChannel, PBAsyncOpen)
ASSERT_EQ(isPrivate, true);
MOZ_ALWAYS_TRUE(mozilla::SpinEventLoopUntil(
"TEST(TestHttpChannel, PBAsyncOpen)"_ns,
[&]() -> bool { return listener->mOnStop.isSome(); }));
}

Просмотреть файл

@ -184,7 +184,9 @@ TEST(TestNsMIMEInputStream, AsyncInputStreamLength)
nsresult rv = qi->AsyncLengthWait(callback, GetCurrentSerialEventTarget());
ASSERT_EQ(NS_OK, rv);
MOZ_ALWAYS_TRUE(SpinEventLoopUntil([&]() { return callback->Called(); }));
MOZ_ALWAYS_TRUE(SpinEventLoopUntil(
"TEST(TestNsMIMEInputStream, AsyncInputStreamLength)"_ns,
[&]() { return callback->Called(); }));
ASSERT_EQ(buf.Length(), callback->Size());
}
@ -218,7 +220,9 @@ TEST(TestNsMIMEInputStream, NegativeAsyncInputStreamLength)
nsresult rv = qi->AsyncLengthWait(callback, GetCurrentSerialEventTarget());
ASSERT_EQ(NS_OK, rv);
MOZ_ALWAYS_TRUE(SpinEventLoopUntil([&]() { return callback->Called(); }));
MOZ_ALWAYS_TRUE(SpinEventLoopUntil(
"TEST(TestNsMIMEInputStream, NegativeAsyncInputStreamLength)"_ns,
[&]() { return callback->Called(); }));
ASSERT_EQ(-1, callback->Size());
}
@ -255,7 +259,9 @@ TEST(TestNsMIMEInputStream, AbortLengthCallback)
rv = qi->AsyncLengthWait(callback2, GetCurrentSerialEventTarget());
ASSERT_EQ(NS_OK, rv);
MOZ_ALWAYS_TRUE(SpinEventLoopUntil([&]() { return callback2->Called(); }));
MOZ_ALWAYS_TRUE(
SpinEventLoopUntil("TEST(TestNsMIMEInputStream, AbortLengthCallback)"_ns,
[&]() { return callback2->Called(); }));
ASSERT_TRUE(!callback1->Called());
ASSERT_EQ(-1, callback2->Size());
}

Просмотреть файл

@ -309,7 +309,9 @@ TEST(TestPartiallySeekableInputStream, AsyncInputStreamLength)
nsresult rv = qi->AsyncLengthWait(callback, GetCurrentSerialEventTarget());
ASSERT_EQ(NS_OK, rv);
MOZ_ALWAYS_TRUE(SpinEventLoopUntil([&]() { return callback->Called(); }));
MOZ_ALWAYS_TRUE(SpinEventLoopUntil(
"TEST(TestPartiallySeekableInputStream, AsyncInputStreamLength)"_ns,
[&]() { return callback->Called(); }));
ASSERT_EQ(buf.Length(), callback->Size());
}
@ -333,7 +335,9 @@ TEST(TestPartiallySeekableInputStream, NegativeAsyncInputStreamLength)
nsresult rv = qi->AsyncLengthWait(callback, GetCurrentSerialEventTarget());
ASSERT_EQ(NS_OK, rv);
MOZ_ALWAYS_TRUE(SpinEventLoopUntil([&]() { return callback->Called(); }));
MOZ_ALWAYS_TRUE(SpinEventLoopUntil(
"TEST(TestPartiallySeekableInputStream, NegativeAsyncInputStreamLength)"_ns,
[&]() { return callback->Called(); }));
ASSERT_EQ(-1, callback->Size());
}
@ -360,7 +364,9 @@ TEST(TestPartiallySeekableInputStream, AbortLengthCallback)
rv = qi->AsyncLengthWait(callback2, GetCurrentSerialEventTarget());
ASSERT_EQ(NS_OK, rv);
MOZ_ALWAYS_TRUE(SpinEventLoopUntil([&]() { return callback2->Called(); }));
MOZ_ALWAYS_TRUE(SpinEventLoopUntil(
"TEST(TestPartiallySeekableInputStream, AbortLengthCallback)"_ns,
[&]() { return callback2->Called(); }));
ASSERT_TRUE(!callback1->Called());
ASSERT_EQ(-1, callback2->Size());
}
@ -380,7 +386,9 @@ TEST(TestPartiallySeekableInputStream, AsyncWaitAfterConsumed)
nsresult rv = psis->AsyncWait(callback, 0, 0, GetCurrentSerialEventTarget());
ASSERT_EQ(NS_OK, rv);
MOZ_ALWAYS_TRUE(SpinEventLoopUntil([&]() { return callback->Called(); }));
MOZ_ALWAYS_TRUE(SpinEventLoopUntil(
"TEST(TestPartiallySeekableInputStream, AsyncWaitAfterConsumed) 1"_ns,
[&]() { return callback->Called(); }));
char rdbuf[bufsize] = {'\0'};
uint32_t count;
@ -392,7 +400,9 @@ TEST(TestPartiallySeekableInputStream, AsyncWaitAfterConsumed)
rv = psis->AsyncWait(callback, 0, 0, GetCurrentSerialEventTarget());
ASSERT_EQ(NS_OK, rv);
MOZ_ALWAYS_TRUE(SpinEventLoopUntil([&]() { return callback->Called(); }));
MOZ_ALWAYS_TRUE(SpinEventLoopUntil(
"TEST(TestPartiallySeekableInputStream, AsyncWaitAfterConsumed) 2"_ns,
[&]() { return callback->Called(); }));
memset(rdbuf, 0x0, bufsize);
ASSERT_EQ(NS_OK, psis->Read(rdbuf, sizeof(rdbuf), &count));
@ -414,7 +424,9 @@ TEST(TestPartiallySeekableInputStream, AsyncWaitAfterClosed)
nsresult rv = psis->AsyncWait(callback, 0, 0, GetCurrentSerialEventTarget());
ASSERT_EQ(NS_OK, rv);
MOZ_ALWAYS_TRUE(SpinEventLoopUntil([&]() { return callback->Called(); }));
MOZ_ALWAYS_TRUE(SpinEventLoopUntil(
"TEST(TestPartiallySeekableInputStream, AsyncWaitAfterClosed) 1"_ns,
[&]() { return callback->Called(); }));
ASSERT_EQ(NS_OK, psis->Close());
@ -423,7 +435,9 @@ TEST(TestPartiallySeekableInputStream, AsyncWaitAfterClosed)
rv = psis->AsyncWait(callback, 0, 0, GetCurrentSerialEventTarget());
ASSERT_EQ(NS_OK, rv);
MOZ_ALWAYS_TRUE(SpinEventLoopUntil([&]() { return callback->Called(); }));
MOZ_ALWAYS_TRUE(SpinEventLoopUntil(
"TEST(TestPartiallySeekableInputStream, AsyncWaitAfterClosed) 2"_ns,
[&]() { return callback->Called(); }));
}
TEST(TestPartiallySeekableInputStream, AsyncLengthWaitAfterClosed)
@ -442,7 +456,9 @@ TEST(TestPartiallySeekableInputStream, AsyncLengthWaitAfterClosed)
nsresult rv = qi->AsyncLengthWait(callback, GetCurrentSerialEventTarget());
ASSERT_EQ(NS_OK, rv);
MOZ_ALWAYS_TRUE(SpinEventLoopUntil([&]() { return callback->Called(); }));
MOZ_ALWAYS_TRUE(SpinEventLoopUntil(
"TEST(TestPartiallySeekableInputStream, AsyncLengthWaitAfterClosed) 1"_ns,
[&]() { return callback->Called(); }));
ASSERT_EQ(buf.Length(), callback->Size());
ASSERT_EQ(NS_OK, psis->Close());
@ -452,7 +468,9 @@ TEST(TestPartiallySeekableInputStream, AsyncLengthWaitAfterClosed)
rv = qi->AsyncLengthWait(callback, GetCurrentSerialEventTarget());
ASSERT_EQ(NS_OK, rv);
MOZ_ALWAYS_TRUE(SpinEventLoopUntil([&]() { return callback->Called(); }));
MOZ_ALWAYS_TRUE(SpinEventLoopUntil(
"TEST(TestPartiallySeekableInputStream, AsyncLengthWaitAfterClosed) 2"_ns,
[&]() { return callback->Called(); }));
ASSERT_EQ(-1, callback->Size());
}
@ -473,7 +491,9 @@ TEST(TestPartiallySeekableInputStream, AsyncLengthWaitAfterConsumed)
nsresult rv = qi->AsyncLengthWait(callback, GetCurrentSerialEventTarget());
ASSERT_EQ(NS_OK, rv);
MOZ_ALWAYS_TRUE(SpinEventLoopUntil([&]() { return callback->Called(); }));
MOZ_ALWAYS_TRUE(SpinEventLoopUntil(
"TEST(TestPartiallySeekableInputStream, AsyncLengthWaitAfterConsumed) 1"_ns,
[&]() { return callback->Called(); }));
ASSERT_EQ(buf.Length(), callback->Size());
char rdbuf[bufsize] = {'\0'};
@ -486,7 +506,9 @@ TEST(TestPartiallySeekableInputStream, AsyncLengthWaitAfterConsumed)
rv = qi->AsyncLengthWait(callback, GetCurrentSerialEventTarget());
ASSERT_EQ(NS_OK, rv);
MOZ_ALWAYS_TRUE(SpinEventLoopUntil([&]() { return callback->Called(); }));
MOZ_ALWAYS_TRUE(SpinEventLoopUntil(
"TEST(TestPartiallySeekableInputStream, AsyncLengthWaitAfterConsumed) 2"_ns,
[&]() { return callback->Called(); }));
ASSERT_EQ(0U, callback->Size());
memset(rdbuf, 0x0, bufsize);