Skip to content

Commit

Permalink
test: Add loop to test_concurrent_field_update_publishing()
Browse files Browse the repository at this point in the history
The previous failure of this test was intermittend, because of the
random timeout in the reset-origin mechanism. To catch more different
random timings, we now run the test in a loop.
  • Loading branch information
mhthies committed Apr 2, 2024
1 parent b6dc786 commit 066fe18
Showing 1 changed file with 20 additions and 19 deletions.
39 changes: 20 additions & 19 deletions test/test_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,25 +238,26 @@ async def test_two_exchange_concurrent_update(self) -> None:

@async_test
async def test_concurrent_field_update_publishing(self) -> None:
var1 = shc.Variable(ExampleTupleType)
exchange = shc.misc.UpdateExchange(ExampleTupleType)\
.connect(var1)
var3 = shc.Variable(int)\
.connect(exchange.field('a'))
# For the back-direction to field-subscription, we do a manual up-conversion
var3.subscribe(exchange, convert=lambda a: ExampleTupleType(a, 3.1416))

writable1 = ExampleWritable(int).connect(var1.field('a'))
writable3 = ExampleWritable(int).connect(var3)

await asyncio.gather(var1.write(ExampleTupleType(42, 3.1416), []), var3.write(56, []))
await asyncio.sleep(0.1)
self.assertEqual(await var1.field('a').read(), await var3.read())

self.assertLessEqual(writable1._write.call_count, 3)
self.assertLessEqual(writable3._write.call_count, 3)
# 1st arg of 2nd call shall be equal
self.assertEqual(writable1._write.call_args[0][0], writable3._write.call_args[0][0])
for i in range(50):
var1 = shc.Variable(ExampleTupleType, "var1")
exchange = shc.misc.UpdateExchange(ExampleTupleType)\
.connect(var1)
var3 = shc.Variable(int, "var3")\
.connect(exchange.field('a'))
# For the back-direction to field-subscription, we do a manual up-conversion
var3.subscribe(exchange, convert=lambda a: ExampleTupleType(a, 3.1416))

writable1 = ExampleWritable(int).connect(var1.field('a'))
writable3 = ExampleWritable(int).connect(var3)

await asyncio.gather(var1.write(ExampleTupleType(42, 3.1416), []), var3.write(56, []))
await asyncio.sleep(0.2)
self.assertEqual(await var1.field('a').read(), await var3.read())

self.assertLessEqual(writable1._write.call_count, 4)
self.assertLessEqual(writable3._write.call_count, 4)
# 1st arg of 2nd call shall be equal
self.assertEqual(writable1._write.call_args[0][0], writable3._write.call_args[0][0])


class ExampleAdderFunctionBlock:
Expand Down

0 comments on commit 066fe18

Please sign in to comment.