Uploaded image for project: 'Drivers'
  1. Drivers
  2. DRIVERS-3183

Support raw-TCP connection test entities

    • Type: Icon: Improvement Improvement
    • Resolution: Unresolved
    • Priority: Icon: Unknown Unknown
    • None
    • Component/s: Unified Test Runner
    • None
    • Needed - No Spec Changes

      Summary

      Simulate network-level behaviors (timeouts, partial responses, connection closures) from within unified tests. Would require at least two new entity types: mockServer and connection. The behavior for mockServer entity should be to spin up a TCP listener and run through the actions in order for each incoming connection.

      The structure for mockServer would be:

      • id: Required string. Unique name for this entity.
      • port: Optional string. TCP port to bind the server. If this value is omitted the test runner picks a free ephemeral port for you.
      • actions: Optional array. These are the socket-level steps–each step is one of:
        • receive: Optional string. Hex string; the server will block until the client sends these bytes.
        • send: Optional string. Hex string; the server will write these bytes back to the client.
        • pause: Optional number. Await this number of milliseconds

      The structure for connection would be:

      • id: Required string. Unique name for this entity.
      • server: Required string. The mockServer.id that this connection should use; the runner will look up it’s actual port.
      • timeoutMS: Optional number. The socket timeout.
        observeEvents: Optional array. Lets you subscribe to CMAP events.

      Additional operations required for mockServer: startMockServer, stopMockServer

      Additional operations required for connection: connectConnection, checkOutConnection, readFromConnection, writeToConnection, checkInConnection.

      For example, consider a test for DRIVERS-2884 where we are required to check aliveness of a connection in “pending response” state if the pending response timeout has been exceeded. To do this we need to verify if the socket can consume 1 byte from the inbound TCP buffer:

      description: "pending response aliveness check"
      schemaVersion: 1.23
      
      createEntities: 
      	- mockServer:
      		id: &mock0 mock0
      		actions:
      			- send: "0c000000000001" 
            			- pause 20
      
      	- connection:
      		id: &conn0 conn0
      		server: *mock0
      		observerEvents:
      			- ConnectionPendingResponseStarted
      			- ConnectionPendingResponseFailed
      			- ConnectionPendingResponseSucceeded 
      
      tests:
      	- description: "pending response aliveness check fails"
      	  operations:
      	  	- name: startMockServer
      		  object: testRunner
      		  arguments:
      		  	server: *mock0
      		
      		# dial the server
      		- name: connectConnection
      		  object: *conn0
      
      		- name: checkOutConnection
      		  object: *conn0
      		
      		# attempt to read 9 bytes within 10ms which should timeout
      		- name: readFromConnection
      		  object: *conn0
      		  arguments: 
      			length: 9
      			timeoutMS: 10
      		  expectedError: 
      			isTimeoutError: true 
      
      		- name: checkInConnection
      		  object: *conn0
      
      		- name: wait
      		  object: testRunner
      		  argument: 
      			ms: 3000 # pending read timeout
      		
      		# the mock server doesn't send anything new so aliveness fails
      		- name: checkOutConnection
      		  object: *conn0
      		  expectedError:
      			isError: true # io.EOF in Go, for example.
      
      
         	     expectEvents: # TODO
      

      Motivation

      Who is the affected end user?

      Driver developers

      Needed by e.g. Atlas, Shell, Compass?

      Is this ticket only for tests?

      Yes.

      Acceptance Criteria

      Review the above suggestion and suggest a PR to simulate network-level behaviors in the unified spec test. If accepted, follow up with a DRIVERS ticket to migrate cmap-format tests to the unified spec runner.

            Assignee:
            Unassigned Unassigned
            Reporter:
            preston.vasquez@mongodb.com Preston Vasquez
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: