Skip to content

Commit

Permalink
Fix too low response timeouts in unit tests
Browse files Browse the repository at this point in the history
The response timeout of the client must be higher than the server
to handle sleep/flush operations done on server side.
  • Loading branch information
stephane committed Oct 21, 2014
1 parent 7e42fcf commit d69c8cf
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion tests/unit-test-client.c
Expand Up @@ -746,6 +746,16 @@ int send_crafted_request(modbus_t *ctx, int function,
const int EXCEPTION_RC = 2;
uint8_t rsp[MODBUS_TCP_MAX_ADU_LENGTH];
int j;
uint32_t old_response_to_sec;
uint32_t old_response_to_usec;

/* This requests can generate flushes server side so we need a higher
* response timeout than the server. The server uses the defined response
* timeout to sleep before flushing.
* The old timeouts are restored at the end.
*/
modbus_get_response_timeout(ctx, &old_response_to_sec, &old_response_to_usec);
modbus_set_response_timeout(ctx, 0, 600000);

for (j=0; j<2; j++) {
int rc;
Expand Down Expand Up @@ -781,8 +791,9 @@ int send_crafted_request(modbus_t *ctx, int function,
rsp[backend_offset] == (0x80 + function) &&
rsp[backend_offset + 1] == MODBUS_EXCEPTION_ILLEGAL_DATA_VALUE, "");
}

modbus_set_response_timeout(ctx, old_response_to_sec, old_response_to_usec);
return 0;
close:
modbus_set_response_timeout(ctx, old_response_to_sec, old_response_to_usec);
return -1;
}

0 comments on commit d69c8cf

Please sign in to comment.