Skip to content

Commit 2e0da3d

Browse files
author
Sergio García Prado
authored
Merge pull request #443 from minos-framework/issue-442-fix-lock-composeddatabaseoperation
#442 - Fix bug related with locking and `ComposedDatabaseOperation`
2 parents e1e1918 + d18e39f commit 2e0da3d

File tree

2 files changed

+10
-5
lines changed
  • packages/core/minos-microservice-common
    • minos/common/database/clients
    • tests/test_common/test_database/test_clients

2 files changed

+10
-5
lines changed

packages/core/minos-microservice-common/minos/common/database/clients/abc.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,14 @@ async def execute(self, operation: DatabaseOperation) -> None:
9999
await self._create_lock(operation.lock)
100100

101101
if isinstance(operation, ComposedDatabaseOperation):
102-
for op in operation.operations:
103-
await wait_for(self._execute(op), operation.timeout)
102+
await wait_for(self._execute_composed(operation), operation.timeout)
104103
else:
105104
await wait_for(self._execute(operation), operation.timeout)
106105

106+
async def _execute_composed(self, operation: ComposedDatabaseOperation) -> None:
107+
for op in operation.operations:
108+
await self.execute(op)
109+
107110
@abstractmethod
108111
async def _execute(self, operation: DatabaseOperation) -> None:
109112
raise NotImplementedError

packages/core/minos-microservice-common/tests/test_common/test_database/test_clients/test_abc.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,13 +133,15 @@ async def test_execute(self):
133133
self.assertEqual([call(operation)], mock.call_args_list)
134134

135135
async def test_execute_composed(self):
136-
mock = AsyncMock()
137136
client = _DatabaseClient()
138-
client._execute = mock
137+
mock = AsyncMock(side_effect=client.execute)
138+
client.execute = mock
139139
composed = ComposedDatabaseOperation([_DatabaseOperation(), _DatabaseOperation()])
140140
await client.execute(composed)
141141

142-
self.assertEqual([call(composed.operations[0]), call(composed.operations[1])], mock.call_args_list)
142+
self.assertEqual(
143+
[call(composed), call(composed.operations[0]), call(composed.operations[1])], mock.call_args_list
144+
)
143145

144146
async def test_execute_with_lock(self):
145147
op1 = _DatabaseOperation(lock="foo")

0 commit comments

Comments
 (0)