Skip to content

Commit

Permalink
Warn if editor session manager socket cannot be created.
Browse files Browse the repository at this point in the history
  • Loading branch information
sleexyz committed Jun 20, 2023
1 parent 5d3c9ed commit 26c1bdd
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 3 deletions.
6 changes: 5 additions & 1 deletion src/node/vscodeSocket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,11 @@ export async function makeEditorSessionManagerServer(
})

const server = http.createServer(router)
await listen(server, { socket: codeServerSocketPath })
try {
await listen(server, { socket: codeServerSocketPath })
} catch (e) {
logger.warn(`Could not create socket at ${codeServerSocketPath}`)
}
return server
}

Expand Down
38 changes: 36 additions & 2 deletions test/unit/node/vscodeSocket.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,39 @@
import { EditorSessionManager } from "../../../src/node/vscodeSocket"
import { clean, tmpdir, listenOn } from "../../utils/helpers"
import { logger } from "@coder/logger"
import * as app from "../../../src/node/app"
import { EditorSessionManager, makeEditorSessionManagerServer } from "../../../src/node/vscodeSocket"
import { clean, tmpdir, listenOn, mockLogger } from "../../utils/helpers"

describe("makeEditorSessionManagerServer", () => {
let tmpDirPath: string

const testName = "mesms"

beforeAll(async () => {
jest.clearAllMocks()
mockLogger()
await clean(testName)
})

afterAll(() => {
jest.resetModules()
})

beforeEach(async () => {
tmpDirPath = await tmpdir(testName)
})

it("warns if socket cannot be created", async () => {
jest.spyOn(app, "listen").mockImplementation(() => {
throw new Error()
})
const server = await makeEditorSessionManagerServer(
`${tmpDirPath}/code-server-ipc.sock`,
new EditorSessionManager(),
)
expect(logger.warn).toHaveBeenCalledWith(`Could not create socket at ${tmpDirPath}/code-server-ipc.sock`)
server.close()
})
})

describe("EditorSessionManager", () => {
let tmpDirPath: string
Expand Down

0 comments on commit 26c1bdd

Please sign in to comment.