OSDN Git Service

Fix flaky EagerReaderTest.test_large_data_multibyte
authorAndre Eisenbach <eisenbach@google.com>
Fri, 20 Nov 2015 19:41:16 +0000 (11:41 -0800)
committerAndre Eisenbach <eisenbach@google.com>
Fri, 20 Nov 2015 19:50:51 +0000 (11:50 -0800)
eager_reader_read() makes no guarantee that the number of bytes read
equals the number of bytes to be read. Insisting that it must in the
test can lead to race conditions where not all data is read at once and
the test fails.

Adjusted test to match API promise.

Change-Id: I5df4b6d8df61d0601402511bb3d9f29f22378981

osi/test/eager_reader_test.cpp

index 65c1dbd..6848cca 100644 (file)
@@ -99,14 +99,14 @@ static void expect_data(eager_reader_t *reader, void *context) {
 
 static void expect_data_multibyte(eager_reader_t *reader, void *context) {
   char *data = (char *)context;
-  int length = strlen(data);
+  size_t length = strlen(data);
 
-  for (int i = 0; i < length;) {
+  for (size_t i = 0; i < length;) {
     uint8_t buffer[28];
-    int bytes_to_read = (length - i) > 28 ? 28 : (length - i);
-    int bytes_read = eager_reader_read(reader, buffer, bytes_to_read, false);
-    EXPECT_EQ(bytes_to_read, bytes_read);
-    for (int j = 0; j < bytes_read && i < length; j++, i++) {
+    size_t bytes_to_read = (length - i) > 28 ? 28 : (length - i);
+    size_t bytes_read = eager_reader_read(reader, buffer, bytes_to_read, false);
+    EXPECT_LE(bytes_read, bytes_to_read);
+    for (size_t j = 0; j < bytes_read && i < length; j++, i++) {
       EXPECT_EQ(data[i], buffer[j]);
     }
   }