Skip to content

Commit bdfc616

Browse files
shunpingash6898
authored andcommitted
Fix flaky MatrixPowerTest.test_basics by reading all generated shards (apache#38585)
* Fix flaky MatrixPowerTest.test_basics by reading all generated shards * Address comments.
1 parent 38600b8 commit bdfc616

1 file changed

Lines changed: 10 additions & 3 deletions

File tree

sdks/python/apache_beam/examples/matrix_power_test.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
"""Test for the matrix power integration test."""
1919

20+
import glob
2021
import logging
2122
import tempfile
2223
import unittest
@@ -51,9 +52,15 @@ def test_basics(self):
5152
'--input_matrix=%s --input_vector=%s --exponent=%d --output=%s.result' %
5253
(matrix_path, vector_path, self.EXPONENT, vector_path)).split())
5354
# Parse result file and compare.
54-
with open(vector_path + '.result-00000-of-00001') as result_file:
55-
results = result_file.read()
56-
self.assertEqual(sorted(self.EXPECTED_OUTPUT), sorted(results))
55+
shard_paths = glob.glob(vector_path + '.result*')
56+
self.assertTrue(
57+
shard_paths,
58+
'No output shards found matching prefix: %s.result' % vector_path)
59+
results = []
60+
for path in shard_paths:
61+
with open(path) as result_file:
62+
results.append(result_file.read())
63+
self.assertEqual(sorted(self.EXPECTED_OUTPUT), sorted(''.join(results)))
5764

5865

5966
if __name__ == '__main__':

0 commit comments

Comments
 (0)