Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit bde75914 authored by Andre Eisenbach's avatar Andre Eisenbach
Browse files

Fix flaky EagerReaderTest.test_large_data_multibyte

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
parent 92108756
Loading
Loading
Loading
Loading
+6 −6
Original line number Diff line number Diff line
@@ -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]);
    }
  }