MCPcopy Create free account
hub / github.com/apache/thrift / BOOST_AUTO_TEST_CASE

Function BOOST_AUTO_TEST_CASE

lib/cpp/test/TFileTransportTest.cpp:172–219  ·  view source on GitHub ↗

* Make sure the TFileTransport destructor exits "quickly". * * Previous versions had a bug causing the writer thread not to exit * right away. * * It's kind of lame that we just check to see how long the destructor takes in * wall-clock time. This could result in false failures on slower systems, or * on heavily loaded machines. */

Source from the content-addressed store, hash-verified

170 * on heavily loaded machines.
171 */
172BOOST_AUTO_TEST_CASE(test_destructor) {
173 TempFile f(tmp_dir, "thrift.TFileTransportTest.");
174
175 unsigned int const NUM_ITERATIONS = 1000;
176
177 unsigned int num_over = 0;
178 for (unsigned int n = 0; n < NUM_ITERATIONS; ++n) {
179 BOOST_CHECK_EQUAL(0, ftruncate(f.getFD(), 0));
180
181 TFileTransport* transport = new TFileTransport(f.getPath());
182
183 // write something so that the writer thread gets started
184 transport->write(reinterpret_cast<const uint8_t*>("foo"), 3);
185
186 // Every other iteration, also call flush(), just in case that potentially
187 // has any effect on how the writer thread wakes up.
188 if (n & 0x1) {
189 transport->flush();
190 }
191
192 /*
193 * Time the call to the destructor
194 */
195 struct timeval start;
196 struct timeval end;
197
198 THRIFT_GETTIMEOFDAY(&start, nullptr);
199 delete transport;
200 THRIFT_GETTIMEOFDAY(&end, nullptr);
201
202 int delta = time_diff(&start, &end);
203
204 // If any attempt takes more than 500ms, treat that as a failure.
205 // Treat this as a fatal failure, so we'll return now instead of
206 // looping over a very slow operation.
207 BOOST_WARN( delta < 500000 );
208
209 // Normally, it takes less than 100ms on my dev box.
210 // However, if the box is heavily loaded, some of the test runs
211 // take longer, since we're just waiting for our turn on the CPU.
212 if (delta > 100000) {
213 ++num_over;
214 }
215 }
216
217 // Make sure fewer than 10% of the runs took longer than 1000us
218 BOOST_WARN(num_over < (NUM_ITERATIONS / 10));
219}
220
221/**
222 * Make sure setFlushMaxUs() is honored.

Callers

nothing calls this directly

Calls 6

time_diffFunction · 0.85
test_flush_max_us_implFunction · 0.85
writeMethod · 0.65
getFDMethod · 0.45
getPathMethod · 0.45
flushMethod · 0.45

Tested by

no test coverage detected