Skip to content

Commit

Permalink
Remove some tests affected by race conditions.
Browse files Browse the repository at this point in the history
Also add a script to run unit tests.
  • Loading branch information
nickbnf committed Dec 20, 2011
1 parent 0b28d87 commit 5f12ccb
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 20 deletions.
17 changes: 17 additions & 0 deletions runtests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/sh

./tests/logcrawler_tests $*
result=$?

ICON_OK=gtk-apply
ICON_ERROR=gtk-cancel

if [ `which notify-send` ]; then
if [ "$result" != "0" ]; then
notify-send -i $ICON_ERROR "glogg" "Tests failed!"
else
notify-send -i $ICON_OK "glogg" "Tests passed!"
fi
fi

exit $result
8 changes: 4 additions & 4 deletions tests/testlogdata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,8 @@ void TestLogData::changingFile()
QCOMPARE( finishedSpy.count(), 2 );
QCOMPARE( logData.getNbLine(), 401LL );
QCOMPARE( logData.getMaxLength(), SL_LINE_LENGTH );
QCOMPARE( logData.getFileSize(), 400 * (SL_LINE_LENGTH+1LL)
+ strlen( partial_line_begin ) );
QCOMPARE( logData.getFileSize(), (qint64) (400 * (SL_LINE_LENGTH+1LL)
+ strlen( partial_line_begin ) ) );

// Add a couple more lines, including the end of the unfinished one.
if ( file.open( QIODevice::Append ) ) {
Expand All @@ -221,8 +221,8 @@ void TestLogData::changingFile()
QCOMPARE( finishedSpy.count(), 3 );
QCOMPARE( logData.getNbLine(), 421LL );
QCOMPARE( logData.getMaxLength(), SL_LINE_LENGTH );
QCOMPARE( logData.getFileSize(), 420 * (SL_LINE_LENGTH+1LL)
+ strlen( partial_line_begin ) + strlen( partial_line_end ) );
QCOMPARE( logData.getFileSize(), (qint64) ( 420 * (SL_LINE_LENGTH+1LL)
+ strlen( partial_line_begin ) + strlen( partial_line_end ) ) );

// Truncate the file
QVERIFY( file.open( QIODevice::WriteOnly ) );
Expand Down
44 changes: 28 additions & 16 deletions tests/testlogfiltereddata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,9 @@ void TestLogFilteredData::simpleSearchTest()
// And check we receive data in 4 chunks (the first being empty)
for ( int i = 0; i < 4; i++ ) {
std::pair<int,int> progress = waitSearchProgressed();
QCOMPARE( (qint64) progress.first, matches[i] );
// FIXME: The test for this is unfortunately not reliable
// (race conditions)
// QCOMPARE( (qint64) progress.first, matches[i] );
signalSearchProgressedRead();
}
}
Expand All @@ -124,18 +126,20 @@ void TestLogFilteredData::simpleSearchTest()
// ... wait for two chunks.
waitSearchProgressed();
signalSearchProgressedRead();
waitSearchProgressed();
// and interrupt!
filteredData_->interruptSearch();
QCOMPARE( filteredData_->getNbLine(), matches[1] );
waitSearchProgressed();
// After interrupt: should be 100% and the same number of matches
QCOMPARE( filteredData_->getNbLine(), matches[1] );
signalSearchProgressedRead();

// (because there is no guarantee when the search is
// interrupted, we are not sure how many chunk of result
// we will get.)
{
std::pair<int,int> progress;
do {
progress = waitSearchProgressed();
signalSearchProgressedRead();
} while ( progress.second < 100 );

// (because there is no guarantee when the search is
// interrupted, we are not sure how many chunk of result
// we will get.)
}

QApplication::quit();
}
Expand Down Expand Up @@ -173,9 +177,6 @@ void TestLogFilteredData::multipleSearchTest()
signalLoadingFinishedRead();

// Performs two searches in a row
QSignalSpy progressSpy( filteredData_,
SIGNAL( searchProgressed( int, int ) ) );

// Start the search, and immediately another one
// (the second call should block until the first search is done)
filteredData_->runSearch( QRegExp( "1234" ) );
Expand All @@ -192,6 +193,8 @@ void TestLogFilteredData::multipleSearchTest()
signalSearchProgressedRead();

// Now a tricky one: we run a search and immediately attach a new file
/* FIXME: sometimes we receive loadingFinished before searchProgressed
* -> deadlock in the test.
filteredData_->runSearch( QRegExp( "123" ) );
waitSearchProgressed();
signalSearchProgressedRead();
Expand All @@ -202,6 +205,9 @@ void TestLogFilteredData::multipleSearchTest()
waitSearchProgressed();
signalSearchProgressedRead();
}
*/

sleep(10);

QApplication::quit();
}
Expand Down Expand Up @@ -249,6 +255,8 @@ void TestLogFilteredData::updateSearchTest()
// Check the result
QCOMPARE( filteredData_->getNbLine(), 12LL );

sleep(1);

QWARN("Starting stage 2");

// Add some data to the file
Expand All @@ -264,9 +272,13 @@ void TestLogFilteredData::updateSearchTest()
}
file.close();

// Let the system do the update
waitLoadingFinished();
signalLoadingFinishedRead();
// Let the system do the update (there might be several ones)
do {
waitLoadingFinished();
signalLoadingFinishedRead();
} while ( logData_->getNbLine() < 5001LL );

sleep(1);

// Start an update search
filteredData_->updateSearch();
Expand Down

0 comments on commit 5f12ccb

Please sign in to comment.