TEST(AutoResetEvent, TimedWait) { AutoResetEvent event; EXPECT_FALSE(event.TimedWait(1)); event.Set(); EXPECT_TRUE(event.TimedWait(1)); EXPECT_FALSE(event.TryWait()); }
void PerfTest::StartListener() { wstring localFqdn; auto error = TcpTransportUtility::GetLocalFqdn(localFqdn); Invariant(error.IsSuccess()); for (USHORT port = 22000; port < 23000; ++port) { listener_ = TcpDatagramTransport::Create(wformatString("{0}:{1}", localFqdn, port)); SecuritySettings securitySettings = TTestUtil::CreateTestSecuritySettings(securityProvider_, protectionLevel); Invariant(listener_->SetSecurity(securitySettings).IsSuccess()); auto root = make_shared<TestRoot>(); // make it real! listener_->SetMessageHandler([this, root](MessageUPtr & receivedMsg, ISendTarget::SPtr const & st) { auto after = ++recvCount_; recvBytes_ += receivedMsg->SerializedSize(); if (after == 1) { console.WriteLine("send test parameters to {0}:{1}", st->Address(), testParameters_); auto msg = make_unique<Message>(testParameters_); listener_->SendOneWay(st, move(msg)); return; } if (after == 2) { stopwatch_.Start(); if (after < (testParameters_.MessageCount() + 1)) { return; } } if (after == (testParameters_.MessageCount() + 1)) { stopwatch_.Stop(); allReceived_.Set(); // stop sending side auto msg = make_unique<Message>(); listener_->SendOneWay(st, move(msg)); return; } if (shouldQueueReceivedMessage_) { AcquireWriteLock grab(receiveQueueLock); receiveQueue.push(receivedMsg->Clone()); if (receiveQueue.size() > 8) { receiveQueue.pop(); } } }); error = listener_->Start(); if (!error.IsSuccess()) { Invariant(error.IsError(ErrorCodeValue::AddressAlreadyInUse)); console.WriteLine("!!! address conflict, will retry !!!"); continue; } console.WriteLine("listen address: {0}", listener_->ListenAddress()); break; } }