@@ -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