mirror of
https://github.com/debauchee/barrier.git
synced 2026-05-11 00:58:14 +08:00
Solution attempt for timing bugs in write_bufferRateLimit
It's probably better to wait until the buffer is sent, rather than waiting until its empty. To test the output it has to be sent, but because of timing, it may be emptied at any point.
This commit is contained in:
@@ -19,17 +19,40 @@
|
||||
|
||||
#include "ipc/IpcServer.h"
|
||||
#include "ipc/IpcMessage.h"
|
||||
#include "arch/Arch.h"
|
||||
|
||||
#include "test/global/gmock.h"
|
||||
|
||||
using ::testing::_;
|
||||
using ::testing::Invoke;
|
||||
|
||||
class IEventQueue;
|
||||
|
||||
class MockIpcServer : public IpcServer
|
||||
{
|
||||
public:
|
||||
MockIpcServer() { }
|
||||
MockIpcServer() :
|
||||
m_sendCond(ARCH->newCondVar()),
|
||||
m_sendMutex(ARCH->newMutex()) { }
|
||||
|
||||
MOCK_METHOD0(listen, void());
|
||||
MOCK_METHOD2(send, void(const IpcMessage&, EIpcClientType));
|
||||
MOCK_CONST_METHOD1(hasClients, bool(EIpcClientType));
|
||||
|
||||
void delegateToFake() {
|
||||
ON_CALL(*this, send(_, _)).WillByDefault(Invoke(this, &MockIpcServer::mockSend));
|
||||
}
|
||||
|
||||
void waitForSend() {
|
||||
ARCH->waitCondVar(m_sendCond, m_sendMutex, -1);
|
||||
}
|
||||
|
||||
private:
|
||||
void mockSend(const IpcMessage&, EIpcClientType) {
|
||||
ArchMutexLock lock(m_sendMutex);
|
||||
ARCH->broadcastCondVar(m_sendCond);
|
||||
}
|
||||
|
||||
ArchCond m_sendCond;
|
||||
ArchMutex m_sendMutex;
|
||||
};
|
||||
|
||||
@@ -48,6 +48,7 @@ inline const Matcher<const IpcMessage&> IpcLogLineMessageEq(const String& s) {
|
||||
TEST(IpcLogOutputterTests, write_bufferSizeWrapping)
|
||||
{
|
||||
MockIpcServer mockServer;
|
||||
mockServer.delegateToFake();
|
||||
|
||||
ON_CALL(mockServer, hasClients(_)).WillByDefault(Return(true));
|
||||
|
||||
@@ -61,14 +62,13 @@ TEST(IpcLogOutputterTests, write_bufferSizeWrapping)
|
||||
outputter.write(kNOTE, "mock 1");
|
||||
outputter.write(kNOTE, "mock 2");
|
||||
outputter.write(kNOTE, "mock 3");
|
||||
|
||||
// wait for the buffer to be empty (all lines sent to IPC)
|
||||
outputter.waitForEmpty();
|
||||
mockServer.waitForSend();
|
||||
}
|
||||
|
||||
TEST(IpcLogOutputterTests, write_bufferRateLimit)
|
||||
{
|
||||
MockIpcServer mockServer;
|
||||
mockServer.delegateToFake();
|
||||
|
||||
ON_CALL(mockServer, hasClients(_)).WillByDefault(Return(true));
|
||||
|
||||
@@ -82,14 +82,13 @@ TEST(IpcLogOutputterTests, write_bufferRateLimit)
|
||||
// log 1 more line than the buffer can accept in time limit.
|
||||
outputter.write(kNOTE, "mock 1");
|
||||
outputter.write(kNOTE, "mock 2");
|
||||
outputter.waitForEmpty();
|
||||
mockServer.waitForSend();
|
||||
|
||||
// after waiting the time limit send another to make sure
|
||||
// we can log after the time limit passes.
|
||||
ARCH->sleep(0.01); // 10ms
|
||||
outputter.write(kNOTE, "mock 3");
|
||||
outputter.write(kNOTE, "mock 4");
|
||||
outputter.waitForEmpty();
|
||||
mockServer.waitForSend();
|
||||
}
|
||||
|
||||
#endif // WINAPI_MSWINDOWS
|
||||
|
||||
Reference in New Issue
Block a user