Use unique socket per user for managing editor sessions (#6278)
Also warn if editor session manager socket cannot be created rather than failing.
This commit is contained in:
@ -1,5 +1,50 @@
|
||||
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 { paths } from "../../../src/node/util"
|
||||
import {
|
||||
DEFAULT_SOCKET_PATH,
|
||||
EditorSessionManager,
|
||||
makeEditorSessionManagerServer,
|
||||
} from "../../../src/node/vscodeSocket"
|
||||
import { clean, tmpdir, listenOn, mockLogger } from "../../utils/helpers"
|
||||
|
||||
describe("DEFAULT_SOCKET_PATH", () => {
|
||||
it("should be a unique path per user", () => {
|
||||
expect(DEFAULT_SOCKET_PATH.startsWith(paths.data)).toBe(true)
|
||||
})
|
||||
})
|
||||
|
||||
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
|
||||
|
Reference in New Issue
Block a user