Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: lastElapsedTime for non streaming requests #1162

Merged
merged 1 commit into from
Sep 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -549,11 +549,12 @@ export class Client extends EventEmitter {
return;
}

const startTime = Date.now();
return this.httpClient.request(location, xml, (err, response, body) => {
this.lastResponse = body;
if (response) {
this.lastResponseHeaders = response.headers;
this.lastElapsedTime = response.headers.date;
this.lastElapsedTime = Date.now() - startTime;
this.lastResponseAttachments = response.mtomResponseAttachments;
// Added mostly for testability, but possibly useful for debugging
this.lastRequestHeaders = response.config && response.config.headers;
Expand Down
63 changes: 63 additions & 0 deletions test/client-response-options-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
'use strict';

const fs = require('fs'),
soap = require('../lib/soap'),
http = require('http'),
assert = require('assert');

let server;
const servicePath = '/SayHello';
let url;
const wsdl = fs.readFileSync(__dirname + '/wsdl/hello.wsdl', 'utf-8');
const serviceImplementation = {
Hello_Service: {
Hello_Port: {
sayHello: function (args) {
return {
greeting: args.firstName
};
}
}
}
};

describe('SOAP Client', function () {

before(function (done) {
// start test soap server (hello.wsdl)
server = http.createServer(function (request, response) {
response.end('404: Not Found: ' + request.url);
});
console.log('test server is created');

server.listen(54454, function () {
soap.listen(server, servicePath, serviceImplementation, wsdl);
url = 'http://' + server.address().address + ':' + server.address().port;
if (server.address().address === '0.0.0.0' || server.address().address === '::') {
url = 'http://127.0.0.1:' + server.address().port;
}
console.log('test server is listening in', url);
done();
});
});

after(function () {
server.close();
console.log('server is closed');
});

it('lastElapsedTime is computed', function (done) {
soap.createClientAsync(__dirname + '/wsdl/hello.wsdl', { endpoint: `${url}${servicePath}` }).then(function (client) {
assert.ok(client);
console.log('client created:', client.describe());
client.sayHelloAsync({ firstName: 'LastElapsedTime Tester' }, { time: true }).then(() => {
assert.ok(Object.prototype.hasOwnProperty.call(client, 'lastElapsedTime'));
assert.ok(typeof client.lastElapsedTime === 'number');
console.log('api finished in ms:', client.lastElapsedTime);
assert.ok(client.lastElapsedTime > 0);
done();
});
});
});

});
33 changes: 33 additions & 0 deletions test/wsdl/hello.wsdl
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>
<definitions name="HelloService" targetNamespace="http://www.examples.com/wsdl/HelloService.wsdl" xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://www.examples.com/wsdl/HelloService.wsdl" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<message name="SayHelloRequest">
<part name="firstName" type="xsd:string" />
</message>
<message name="SayHelloResponse">
<part name="greeting" type="xsd:string" />
</message>
<portType name="Hello_PortType">
<operation name="sayHello">
<input message="tns:SayHelloRequest" />
<output message="tns:SayHelloResponse" />
</operation>
</portType>
<binding name="Hello_Binding" type="tns:Hello_PortType">
<soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http" />
<operation name="sayHello">
<soap:operation soapAction="sayHello" />
<input>
<soap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="urn:examples:helloservice" use="encoded" />
</input>
<output>
<soap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="urn:examples:helloservice" use="encoded" />
</output>
</operation>
</binding>
<service name="Hello_Service">
<documentation>WSDL File for HelloService</documentation>
<port binding="tns:Hello_Binding" name="Hello_Port">
<soap:address location="http://localhost:51515/SayHello/" />
</port>
</service>
</definitions>