Skip to content

Commit

Permalink
test: Fix a potential leak or worse in the test (deephaven#6146)
Browse files Browse the repository at this point in the history
This came up as a suspect to a more serious test failure.
  • Loading branch information
jmao-denver authored Sep 27, 2024
1 parent d06d3e2 commit e596689
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 7 deletions.
6 changes: 3 additions & 3 deletions py/client/pydeephaven/ticket.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,11 @@ def __init__(self, ticket_bytes: bytes):
raise DHError('ApplicationTicket: ticket is None')
elif not ticket_bytes.startswith(b'a/'):
raise DHError(f'ApplicationTicket: ticket {ticket_bytes} is not an application ticket')
elif len(ticket_bytes.split(b'/')) != 3:
elif len(ticket_bytes.split(b'/')) != 4:
raise DHError(f'ApplicationTicket: ticket {ticket_bytes} is not in the correct format')

self.app_id = ticket_bytes.split(b'/')[1].decode(encoding='ascii')
self.field = ticket_bytes.split(b'/')[2].decode(encoding='ascii')
self.field = ticket_bytes.split(b'/')[3].decode(encoding='ascii')

super().__init__(ticket_bytes)

Expand All @@ -169,7 +169,7 @@ def app_ticket(cls, app_id: str, field: str) -> ApplicationTicket:
if not field:
raise DHError('app_ticket: field must be a non-empty string')

return cls(ticket_bytes=f'a/{app_id}/{field}'.encode(encoding='ascii'))
return cls(ticket_bytes=f'a/{app_id}/f/{field}'.encode(encoding='ascii'))


def _ticket_from_proto(ticket: ticket_pb2.Ticket) -> Ticket:
Expand Down
57 changes: 53 additions & 4 deletions py/client/tests/test_plugin_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import unittest

from pydeephaven.session import Session
from pydeephaven.ticket import SharedTicket, ServerObject
from pydeephaven.ticket import SharedTicket, ServerObject, ScopeTicket
from tests.testbase import BaseTestCase


Expand All @@ -14,9 +14,12 @@ def setUp(self) -> None:
server_script = '''
from deephaven.plot.figure import Figure
from deephaven import empty_table
import deephaven.pandas as dhpd
source = empty_table(20).update(["Letter = (i % 2 == 0) ? `A` : `B`", "X = 0.1 * i", "Y = randomDouble(0.0, 5.0)"])
df = dhpd.to_pandas(source)
plot = Figure().plot_xy(series_name="Random numbers", t=source, x="X", y="Y").show()
source2 = empty_table(20).update(["Letter = (i % 2 == 0) ? `A` : `B`", "X = 0.1 * i", "Y = randomDouble(0.0, 5.0)"])
Expand All @@ -36,8 +39,10 @@ def test_create(self):
self.assertGreater(len(refs), 0)
ref = refs[0]
self.assertEqual(ref.type, "Table")
plugin_client.close()

def test_publish_fetch(self):
@unittest.skip("need to wait for https://github.com/deephaven/deephaven-core/issues/5996")
def test_publish_fetch_figure(self):
plugin_client = self.session.plugin_client(self.session.exportable_objects["plot3"])
self.assertIsNotNone(plugin_client)

Expand All @@ -63,7 +68,6 @@ def test_publish_fetch(self):
sub_session.close()

with self.subTest("Fetchable in the Plugin object"):
self.skipTest("need to wait for https://github.com/deephaven/deephaven-core/issues/5996")
payload, refs = next(plugin_client.resp_stream)
self.assertGreater(len(payload), 0)
self.assertGreater(len(refs), 0)
Expand All @@ -85,7 +89,6 @@ def test_publish_fetch(self):
sub_session.close()

with self.subTest("released Plugin object"):
self.skipTest("need to wait for https://github.com/deephaven/deephaven-core/issues/5996")
sub_session = Session()
server_obj = ServerObject(type="Figure", ticket=shared_ticket)
sub_plugin_client = sub_session.plugin_client(server_obj)
Expand All @@ -96,6 +99,52 @@ def test_publish_fetch(self):

plugin_client.close()

@unittest.skip("need to wait for https://github.com/deephaven/deephaven-core/issues/5996")
def test_publish_fetch_pandas(self):
plugin_client = self.session.plugin_client(self.session.exportable_objects["df"])
self.assertIsNotNone(plugin_client)

# First fetch the Plugin object, then publish it
export_plugin_client = self.session.fetch(plugin_client)
shared_ticket = SharedTicket.random_ticket()
self.session.publish(export_plugin_client, shared_ticket)

# Another session to use the shared Plugin object
sub_session = Session()
server_obj = ServerObject(type="pandas.DataFrame", ticket=shared_ticket)
sub_plugin_client = sub_session.plugin_client(server_obj)
payload, refs = next(sub_plugin_client.resp_stream)
self.assertEqual(len(payload), 0)
self.assertEqual(len(refs), 1)
ref = refs[0]
self.assertEqual(ref.type, "Table")
fetched = ref.fetch()
self.assertIsNotNone(fetched)
self.assertEqual(fetched.size, 20)
sub_plugin_client.close()
sub_session.close()

# continue with source plugin client
payload, refs = next(plugin_client.resp_stream)
self.assertEqual(len(payload), 0)
self.assertEqual(len(refs), 1)
ref = refs[0]
self.assertEqual(ref.type, "Table")
fetched = ref.fetch()
self.assertIsNotNone(fetched)
self.assertEqual(fetched.size, 20)
plugin_client.close()

def test_publish_fetch_table(self):
export_ticket = self.session.fetch(ScopeTicket.scope_ticket("source"))
shared_ticket = SharedTicket.random_ticket()
self.session.publish(export_ticket, shared_ticket)

sub_session = Session()
sub_export_ticket = sub_session.fetch(shared_ticket)
sub_table = sub_session.table_service.fetch_etcr(sub_export_ticket.pb_ticket)
self.assertEqual(sub_table.size, 20)


if __name__ == "__main__":
unittest.main()

0 comments on commit e596689

Please sign in to comment.