|
| 1 | +import { join } from 'path' |
| 2 | +import { collectRunningExperimentPids } from './collect' |
| 3 | +import { getPidFromFile } from '../../fileSystem' |
| 4 | +import { |
| 5 | + DVCLIVE_ONLY_RUNNING_SIGNAL_FILE, |
| 6 | + EXP_RWLOCK_FILE |
| 7 | +} from '../../cli/dvc/constants' |
| 8 | + |
| 9 | +jest.mock('../../fileSystem') |
| 10 | + |
| 11 | +const mockedGetPidFromFile = jest.mocked(getPidFromFile) |
| 12 | + |
| 13 | +beforeEach(() => { |
| 14 | + jest.resetAllMocks() |
| 15 | +}) |
| 16 | + |
| 17 | +describe('collectRunningExperimentPids', () => { |
| 18 | + it('should exclude undefined from the final result', async () => { |
| 19 | + mockedGetPidFromFile |
| 20 | + .mockResolvedValueOnce(undefined) |
| 21 | + .mockResolvedValueOnce(1234) |
| 22 | + |
| 23 | + const mockedDvcRoot = join('mock', 'root') |
| 24 | + |
| 25 | + expect(await collectRunningExperimentPids([mockedDvcRoot])).toStrictEqual([ |
| 26 | + 1234 |
| 27 | + ]) |
| 28 | + |
| 29 | + expect(mockedGetPidFromFile).toHaveBeenCalledTimes(2) |
| 30 | + expect(mockedGetPidFromFile).toHaveBeenCalledWith( |
| 31 | + join(mockedDvcRoot, DVCLIVE_ONLY_RUNNING_SIGNAL_FILE) |
| 32 | + ) |
| 33 | + expect(mockedGetPidFromFile).toHaveBeenCalledWith( |
| 34 | + join(mockedDvcRoot, EXP_RWLOCK_FILE) |
| 35 | + ) |
| 36 | + }) |
| 37 | + |
| 38 | + it("should collect the pid of processes which are located in each repository's files", async () => { |
| 39 | + mockedGetPidFromFile |
| 40 | + .mockResolvedValueOnce(1) |
| 41 | + .mockResolvedValueOnce(2) |
| 42 | + .mockResolvedValueOnce(3) |
| 43 | + .mockResolvedValueOnce(4) |
| 44 | + |
| 45 | + const mockedFirstDvcRoot = join('mock', 'root', '1') |
| 46 | + const mockedSecondDvcRoot = join('mock', 'root', '2') |
| 47 | + |
| 48 | + expect( |
| 49 | + await collectRunningExperimentPids([ |
| 50 | + mockedFirstDvcRoot, |
| 51 | + mockedSecondDvcRoot |
| 52 | + ]) |
| 53 | + ).toStrictEqual([1, 2, 3, 4]) |
| 54 | + |
| 55 | + expect(mockedGetPidFromFile).toHaveBeenCalledTimes(4) |
| 56 | + expect(mockedGetPidFromFile).toHaveBeenCalledWith( |
| 57 | + join(mockedFirstDvcRoot, DVCLIVE_ONLY_RUNNING_SIGNAL_FILE) |
| 58 | + ) |
| 59 | + expect(mockedGetPidFromFile).toHaveBeenCalledWith( |
| 60 | + join(mockedFirstDvcRoot, EXP_RWLOCK_FILE) |
| 61 | + ) |
| 62 | + expect(mockedGetPidFromFile).toHaveBeenCalledWith( |
| 63 | + join(mockedSecondDvcRoot, DVCLIVE_ONLY_RUNNING_SIGNAL_FILE) |
| 64 | + ) |
| 65 | + expect(mockedGetPidFromFile).toHaveBeenCalledWith( |
| 66 | + join(mockedSecondDvcRoot, EXP_RWLOCK_FILE) |
| 67 | + ) |
| 68 | + }) |
| 69 | +}) |
0 commit comments