Skip to content

Commit

Permalink
Reconcile/unify browser/native request-response testing
Browse files Browse the repository at this point in the history
  • Loading branch information
bretambrose committed Aug 23, 2024
1 parent 4e82f16 commit b6d8ed7
Show file tree
Hide file tree
Showing 7 changed files with 1,941 additions and 1,172 deletions.
1,068 changes: 410 additions & 658 deletions lib/browser/mqtt_request_response.spec.ts

Large diffs are not rendered by default.

44 changes: 44 additions & 0 deletions lib/browser/mqtt_request_response.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,44 @@ interface ServiceTaskWrapper {
nextServiceTime : number;
}

function areClientOptionsValid(options: mqtt_request_response.RequestResponseClientOptions) : boolean {
if (!options) {
return false;
}

if (!options.maxRequestResponseSubscriptions) {
return false;
}

if (!Number.isInteger(options.maxRequestResponseSubscriptions)) {
return false;
}

if (options.maxRequestResponseSubscriptions < 2) {
return false;
}

if (!options.maxStreamingSubscriptions) {
return false;
}

if (!Number.isInteger(options.maxStreamingSubscriptions)) {
return false;
}

if (options.operationTimeoutInSeconds) {
if (!Number.isInteger(options.operationTimeoutInSeconds)) {
return false;
}

if (options.operationTimeoutInSeconds <= 0) {
return false;
}
}

return true;
}

/**
* Native implementation of an MQTT-based request-response client tuned for AWS MQTT services.
*
Expand All @@ -128,6 +166,10 @@ export class RequestResponseClient extends BufferedEventEmitter implements mqtt_
private operationQueue : Array<number> = new Array<number>;

constructor(protocolClientAdapter: protocol_client_adapter.ProtocolClientAdapter, options: mqtt_request_response.RequestResponseClientOptions) {
if (!areClientOptionsValid(options)) {
throw new CrtError("Invalid client options passed to RequestResponseClient constructor");
}

super();

this.operationTimeoutInSeconds = options.operationTimeoutInSeconds ?? 60;
Expand Down Expand Up @@ -860,5 +902,7 @@ function validateRequestOptions(requestOptions: mqtt_request_response.RequestRes
if (typeof(requestOptions.correlationToken) !== 'string') {
throw new CrtError("Invalid request options - correlationToken is not a string");
}
} else if (requestOptions.correlationToken === null) {
throw new CrtError("Invalid request options - correlationToken null");
}
}
Loading

0 comments on commit b6d8ed7

Please sign in to comment.