| 81 | } |
| 82 | |
| 83 | void TLogTest::TestThreadedWithOverflow() { |
| 84 | class TFakeLogBackend: public TLogBackend { |
| 85 | public: |
| 86 | TWriteGuard Guard() { |
| 87 | return TWriteGuard(Lock_); |
| 88 | } |
| 89 | |
| 90 | void WriteData(const TLogRecord&) override { |
| 91 | TReadGuard guard(Lock_); |
| 92 | } |
| 93 | |
| 94 | void ReopenLog() override { |
| 95 | TWriteGuard guard(Lock_); |
| 96 | } |
| 97 | |
| 98 | private: |
| 99 | TRWMutex Lock_; |
| 100 | }; |
| 101 | |
| 102 | auto waitForFreeQueue = [](const TLog& log) { |
| 103 | ThreadYield(); |
| 104 | while (log.BackEndQueueSize() > 0) { |
| 105 | Sleep(TDuration::MilliSeconds(1)); |
| 106 | } |
| 107 | }; |
| 108 | |
| 109 | TFakeLogBackend fb; |
| 110 | { |
| 111 | TLog log(THolder(new TThreadedLogBackend(&fb, 2))); |
| 112 | |
| 113 | auto guard = fb.Guard(); |
| 114 | log.AddLog("first write"); |
| 115 | waitForFreeQueue(log); |
| 116 | log.AddLog("second write (first in queue)"); |
| 117 | log.AddLog("third write (second in queue)"); |
| 118 | UNIT_ASSERT_EXCEPTION(log.AddLog("fourth write (queue overflow)"), yexception); |
| 119 | } |
| 120 | |
| 121 | { |
| 122 | ui32 overflows = 0; |
| 123 | TLog log(THolder(new TThreadedLogBackend(&fb, 2, [&overflows] { ++overflows; }))); |
| 124 | |
| 125 | auto guard = fb.Guard(); |
| 126 | log.AddLog("first write"); |
| 127 | waitForFreeQueue(log); |
| 128 | log.AddLog("second write (first in queue)"); |
| 129 | log.AddLog("third write (second in queue)"); |
| 130 | UNIT_ASSERT_EQUAL(overflows, 0); |
| 131 | log.AddLog("fourth write (queue overflow)"); |
| 132 | UNIT_ASSERT_EQUAL(overflows, 1); |
| 133 | } |
| 134 | } |
| 135 | |
| 136 | void TLogTest::TestNoFlush() { |
| 137 | { |
nothing calls this directly
no test coverage detected