Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
t.fail('Calling non-routable endpoint failed with unexpected error: ' + e.toString());
}
}
// create a mock server, the mock server wait for 10 seconds until send response
const mockServer = http.createServer((req, res) => {
setTimeout(() => {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.write('Response');
res.end();
}, 10000);
});
mockServer.listen(3000);
// set SO_TIMEOUT to 5000
FabricCAServices.setConfigSetting('socket-operation-timeout', 5000);
// test SO_TIMEOUT
try {
const caClient = new FabricCAServices('http://localhost:3000')._fabricCAClient;
start = Date.now();
await caClient.request('GET', '/aMethod', signingIdentity);
t.fail('Should throw error by SO_TIMEOUT');
} catch (e) {
end = Date.now();
t.equal(Math.floor((end - start) / 1000), 5, 'should have duration roughly equals 5000');
if (e.message.includes('endpoint failed')) {
t.pass('Successfully throw error after SO_TIMEOUT');
} else {
t.fail('did not throw error after SO_TIMEOUT');
}
mockServer.close();
function getFabricCAService() {
FabricCAServices.addConfigFile(path.join(__dirname, 'e2e', 'config.json'));
ORGS = FabricCAServices.getConfigSetting('test-network');
fabricCAEndpoint = ORGS[userOrg].ca.url;
FabricCAServices.getConfigSetting('crypto-keysize', '256');// force for npm test
FabricCAServices.setConfigSetting('crypto-hash-algo', 'SHA2');// force for npm test
return new FabricCAServices(fabricCAEndpoint, tlsOptions, ORGS[userOrg].ca.name);
}