Skip to content

Commit

Permalink
all done
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex committed Nov 22, 2024
1 parent 907623f commit f61d5b8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
10 changes: 8 additions & 2 deletions python/nistoar/midas/dbio/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -901,9 +901,15 @@ def create_record(self, name: str, shoulder: str = None, foruser: str = None) ->
rec.save()
# Send a message through the WebSocket
message = f"{name}"
asyncio.run(self.websocket_server.send_message_to_clients(message))
#print(message)
self._send_message_async(message)
return rec

def _send_message_async(self, message):
loop = asyncio.get_event_loop()
if loop.is_running():
asyncio.create_task(self.websocket_server.send_message_to_clients(message))
else:
asyncio.run(self.websocket_server.send_message_to_clients(message))

def _default_shoulder(self):
out = self._cfg.get("default_shoulder")
Expand Down
12 changes: 3 additions & 9 deletions python/tests/nistoar/midas/dbio/test_inmem.py
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,6 @@ async def receive_messages(uri):
messages.append(message)
#print(f"Messages: {messages}")
# Break the loop after receiving the first message for this test
break
except Exception as e:
print(f"Failed to connect to WebSocket server: {e}")

Expand All @@ -553,17 +552,12 @@ async def receive_messages(uri):

#await self.websocket_server.send_message_to_clients("Connection established")
# Inject some data into the database
await self.websocket_server.send_message_to_clients("test1")
rec = self.cli.create_record("mine1")
await asyncio.sleep(2)
id = "pdr0:0002"
rec = base.ProjectRecord(
base.DMP_PROJECTS, {"id": id, "name": "test 1"}, self.cli)
self.cli._db[base.DMP_PROJECTS][id] = rec.to_dict()


# Assert the number of messages received
#print(f"Messages: {messages}")
self.assertEqual(len(messages), 1)
self.assertEqual(messages[0], "test1")
self.assertEqual(messages[0], "mine1")



Expand Down

0 comments on commit f61d5b8

Please sign in to comment.