@@ -69,21 +69,22 @@ LOG_LEVEL_LIST
6969 log_debug (logging)(" log_debug-test" );
7070 }
7171
72- // Caveat: BufferUpdater is not MT-safe. We use it only for testing.
73- // We would observe missing loglines if we interleaved buffers.
74- // Emit all logs between constructor and destructor of BufferUpdater.
7572 void test_asynclog_drop_messages () {
76- const size_t sz = 2000 ;
73+ const size_t sz = AsyncLogBufferSize / 2 ;
74+ const char * str = " a lot of log..." ;
75+ const size_t str_size = strlen (str);
7776
78- // shrink async buffer.
79- AsyncLogWriter::BufferUpdater saver (1024 );
8077 test_asynclog_ls (); // roughly 200 bytes.
8178 LogMessage (logging) lm;
8279
8380 // write more messages than its capacity in burst
84- for (size_t i = 0 ; i < sz ; ++i) {
85- lm.debug (" a lot of log... " );
81+ for (size_t i = 0 ; i < (sz / str_size) ; ++i) {
82+ lm.debug (" %s " , str );
8683 }
84+ lm.debug (" %s" , str);
85+ lm.debug (" %s" , str);
86+ lm.debug (" %s" , str);
87+ lm.debug (" %s" , str);
8788 lm.flush ();
8889 }
8990
@@ -244,13 +245,34 @@ TEST_VM_F(AsyncLogTest, logBuffer) {
244245}
245246
246247TEST_VM_F (AsyncLogTest, droppingMessage) {
247- if (AsyncLogWriter::instance () == nullptr ) {
248+ if (AsyncLogWriter::instance () == nullptr ) return ;
249+ if (LogConfiguration::async_mode () != LogConfiguration::AsyncMode::Drop) {
250+ FAIL () << " This test must be run in drop mode if async UL is activated" ;
248251 return ;
249252 }
250253
251254 set_log_config (TestLogFileName, " logging=debug" );
252255 test_asynclog_drop_messages ();
253- EXPECT_TRUE (file_contains_substring (TestLogFileName, " messages dropped due to async logging" ));
256+ bool messages_dropped = file_contains_substring (TestLogFileName, " messages dropped due to async logging" );
257+ if (!messages_dropped) {
258+ stringStream content;
259+ FILE* fp = os::fopen (TestLogFileName, " r" );
260+ assert (fp != nullptr , " error opening file %s: %s" , TestLogFileName, os::strerror (errno));
261+ {
262+ ResourceMark rm;
263+ char * line = read_line (fp);
264+ while (line != nullptr ) {
265+ ResourceMark rm;
266+ content.print_raw (line);
267+ line = read_line (fp);
268+ }
269+ }
270+
271+ // The thread is null and deattached.
272+ // That means that UL degrades to synchronous logging for this thread, which means that no messages can be dropped.
273+ EXPECT_NE (nullptr , Thread::current_or_null ()) << " Thread was null" ;
274+ EXPECT_TRUE (messages_dropped) << " Log file content:\n " << content.freeze ();
275+ }
254276}
255277
256278TEST_VM_F (AsyncLogTest, stdoutOutput) {
0 commit comments