Commit d69c8cf9ca7035de60acaf18054d03bccdf36756

Authored by Stéphane Raimbault
1 parent 7e42fcf0

Fix too low response timeouts in unit tests

The response timeout of the client must be higher than the server
to handle sleep/flush operations done on server side.
Showing 1 changed file with 12 additions and 1 deletions
tests/unit-test-client.c
... ... @@ -746,6 +746,16 @@ int send_crafted_request(modbus_t *ctx, int function,
746 746 const int EXCEPTION_RC = 2;
747 747 uint8_t rsp[MODBUS_TCP_MAX_ADU_LENGTH];
748 748 int j;
  749 + uint32_t old_response_to_sec;
  750 + uint32_t old_response_to_usec;
  751 +
  752 + /* This requests can generate flushes server side so we need a higher
  753 + * response timeout than the server. The server uses the defined response
  754 + * timeout to sleep before flushing.
  755 + * The old timeouts are restored at the end.
  756 + */
  757 + modbus_get_response_timeout(ctx, &old_response_to_sec, &old_response_to_usec);
  758 + modbus_set_response_timeout(ctx, 0, 600000);
749 759  
750 760 for (j=0; j<2; j++) {
751 761 int rc;
... ... @@ -781,8 +791,9 @@ int send_crafted_request(modbus_t *ctx, int function,
781 791 rsp[backend_offset] == (0x80 + function) &&
782 792 rsp[backend_offset + 1] == MODBUS_EXCEPTION_ILLEGAL_DATA_VALUE, "");
783 793 }
784   -
  794 + modbus_set_response_timeout(ctx, old_response_to_sec, old_response_to_usec);
785 795 return 0;
786 796 close:
  797 + modbus_set_response_timeout(ctx, old_response_to_sec, old_response_to_usec);
787 798 return -1;
788 799 }
... ...