Skip to content

Commit

Permalink
Trying to close socket too
Browse files Browse the repository at this point in the history
  • Loading branch information
Snafkin547 committed Mar 28, 2024
1 parent f159166 commit 34aa798
Showing 1 changed file with 25 additions and 23 deletions.
48 changes: 25 additions & 23 deletions tests/arithmetics/arithmetics.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ function init_server(port:number){

app.use("../../dist", express.static("../../dist"));
app.use("../../lib/ext", express.static("../../lib/ext"));
app.use("/", express.static("/client"));
app.use("/", express.static("../../lib/client"));

server.listen(port, function () {
console.log("Listening on ", port);
Expand All @@ -16,45 +16,47 @@ function init_server(port:number){
const jiffServer = new JIFFServer(server, { logs: true });

console.log("server is running on port", port);
return server
return [jiffServer, server]
}


describe('JIFF Arithmetic Operations', () => {
let jiffClient1:any;
let jiffClient2:any;
let jiffServer:any;
let server:any;
var entries: {[key:number]:number} = { 1: 60, 2: 60 };
let port:number = 8112

const options = {
party_count: 2,
crypto_provider: true,
};
let computation_id="our-setup-application";

beforeEach(async () => {
server = init_server(port)
await new Promise(resolve => server.on('listening', resolve)); // Wait for server to be ready
// Server Setup
let port:number = 8112
const servers = init_server(port)
jiffServer = servers[0], server = servers[1]

// Client Setup
const JIFFClient = require("../../lib/jiff-client.js");
const serverAddress = server.address();
const serverAddress = jiffServer.address();
const baseUrl = `http://localhost:${serverAddress.port}`;
const options = {
party_count: 2,
crypto_provider: true,
};

jiffClient1 = new JIFFClient(baseUrl, "our-setup-application", options);
jiffClient2 = new JIFFClient(baseUrl, "our-setup-application", options);
port += 1
jiffClient1 = new JIFFClient(baseUrl, computation_id, options);
jiffClient2 = new JIFFClient(baseUrl, computation_id, options);
});

afterEach(async () => {
await new Promise((resolve, reject) => {
server.close((err:any) => {
if (err) {
console.error('Error closing server:', err);
reject(err);
return;
}
resolve(console.log('Server closed'));
});
// Shutting Server
const socket = jiffServer.socketMaps;
console.log(socket)
if (socket) {
socket.disconnect(true); // Disconnect the socket
}
jiffServer.freeComputation(computation_id);
await server.close(() => {
console.log('Server has been closed');
});
});

Expand Down

0 comments on commit 34aa798

Please sign in to comment.