MCPcopy Create free account
hub / github.com/catboost/catboost / TestThreadedWithOverflow

Method TestThreadedWithOverflow

library/cpp/logger/log_ut.cpp:83–134  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

81}
82
83void 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
136void TLogTest::TestNoFlush() {
137 {

Callers

nothing calls this directly

Calls 7

ThreadYieldFunction · 0.85
SleepFunction · 0.85
MilliSecondsFunction · 0.85
THolderClass · 0.50
BackEndQueueSizeMethod · 0.45
GuardMethod · 0.45
AddLogMethod · 0.45

Tested by

no test coverage detected