theintern / leadfoot

A JavaScript client library that brings cross-platform consistency to the Selenium WebDriver API.
Other
170 stars 24 forks source link

Leadfoot prevents process from exiting #150

Open rogierschouten opened 6 years ago

rogierschouten commented 6 years ago

When the Server#createSession() method fails due to a timeout error (selenium hub server not responding), leadfoot does not dispose something and hence the mocha process does not exit.

Reproduce:

  1. create a http server that listens for connections but does not respond to requests
  2. create a session and connect to that http server

code for http server (server.js):

var http = require("http");

var server = http.createServer(() => undefined);
server.listen(4444);

code for leadfoot test (test.js):

var leadfoot = require("@theintern/leadfoot");

describe("foo", function() {
    this.timeout(10E3);

    it("should dispose normally if the hub is not present", async () => {
        var host = "localhost";
        var port = 4444;
        var server = new leadfoot.Server(`http://${host}:${port}/wd/hub`, { timeout: 3000 });
        try {
            await server.createSession({ browserName: "chrome" });
        } catch (error) {
                        // try to dispose anything we can get our hands on
            const sessions = await server.getSessions();
            await Promise.all(sessions.map(async (s) => {
                await s.quit();
                await server.deleteSession(s.sessionId);
            }));
        }
    });
})

Now, run both node server.js and mocha test.js. The test process hangs indefinitely.