Skip to content

Commit 830e2af

Browse files
authored
Ensure IMDServer sends EOF to client DURING test (#5443)
* Fixes #5442 * IMDServer in IMDReader tests now calls disconnect after sending frames so that the client does not rely on the (now 600s) timeout to see the end of the stream - Ensure IMDServer sends EOF to client DURING test - add disconnects to one-off tests * update CHANGELOG * black formatting of test_imd.py
1 parent 3d3a53e commit 830e2af

2 files changed

Lines changed: 20 additions & 1 deletion

File tree

package/CHANGELOG

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,8 @@ Changes
247247
* 2.8.0
248248

249249
Fixes
250+
* Fix `test_imd.py` test failures after imdclient 0.2.4
251+
increased default timeout by ensuring EOF sent (Issue #5442, PR #5443)
250252
* Allows bond/angle/dihedral connectivity to be guessed additively with
251253
`to_guess`, and as a replacement of existing values with `force_guess`.
252254
Also updates cached bond attributes when updating bonds. (Issue #4759, PR #4761)

testsuite/MDAnalysisTests/coordinates/test_imd.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,8 @@ def reader(ref):
217217
)
218218
# Send the rest of the frames- small enough to all fit in socket itself
219219
ref.server.send_frames(1, 5)
220+
# Send EOF so the client does not rely on timeout to mark the end of the stream
221+
ref.server.disconnect()
220222

221223
reader.add_auxiliary(
222224
"lowf",
@@ -249,6 +251,8 @@ def transformed(ref):
249251
)
250252
# Send the rest of the frames- small enough to all fit in socket itself
251253
ref.server.send_frames(1, 5)
254+
# Send EOF so the client does not rely on timeout to mark the end of the stream
255+
ref.server.disconnect()
252256
transformed.add_transformations(
253257
translate([1, 1, 1]), translate([0, 0, 0.33])
254258
)
@@ -436,6 +440,8 @@ def reader(self, universe, imdsinfo):
436440
buffer_size=1 * 1024 * 1024,
437441
)
438442
server.send_frames(1, 5)
443+
# Send EOF so the client does not rely on timeout to mark the end of the stream
444+
server.disconnect()
439445

440446
yield reader
441447
server.cleanup()
@@ -513,6 +519,7 @@ def test_n_atoms_not_specified(universe, imdsinfo):
513519
server = InThreadIMDServer(universe.trajectory)
514520
server.set_imdsessioninfo(imdsinfo)
515521
server.handshake_sequence("localhost", first_frame=True)
522+
# no EOF needed- client should fail before parsing frames
516523
with pytest.raises(
517524
ValueError,
518525
match="IMDReader: n_atoms must be specified",
@@ -535,6 +542,14 @@ def test_imd_stream_empty(universe, imdsinfo):
535542
IMDReader(
536543
f"imd://localhost:{server.port}",
537544
n_atoms=universe.trajectory.n_atoms,
545+
# we have no opportunity to send an EOF here
546+
# since IMDReader creation both establishes a connection
547+
# and attempts to read the first frame, and the EOF
548+
# would have to arrive between these two.
549+
# rather than creating a special IMDServer method that
550+
# immediately sends EOF after handshake,
551+
# just use a 1s timeout passed to IMDClient
552+
timeout=1,
538553
)
539554
server.cleanup()
540555

@@ -549,6 +564,8 @@ def test_create_imd_universe(universe, imdsinfo):
549564
f"imd://localhost:{server.port}",
550565
n_atoms=universe.trajectory.n_atoms,
551566
)
567+
# send EOF after handshake and first frame
568+
server.disconnect()
552569
assert type(u_imd.trajectory).__name__ == "IMDReader"
553570
with pytest.raises(ValueError, match="IMDReader: Invalid IMD URL"):
554571
u_imd = mda.Universe(
@@ -576,7 +593,7 @@ def test_wrong_imd_protocol_version(universe, imdsinfo):
576593
server = InThreadIMDServer(universe.trajectory)
577594
server.set_imdsessioninfo(imdsinfo)
578595
server.handshake_sequence("localhost", first_frame=True)
579-
596+
# no EOF needed- client should fail before parsing frames
580597
with pytest.raises(
581598
ValueError,
582599
match=rf"IMDReader: Detected IMD version v{imdsinfo.version}, "

0 commit comments

Comments
 (0)