Skip to content

Commit

Permalink
chore(server): cleanup library watching (#8835)
Browse files Browse the repository at this point in the history
chore: clean up library watching
  • Loading branch information
jrasm91 authored Apr 16, 2024
1 parent 1c1e461 commit dba3656
Show file tree
Hide file tree
Showing 23 changed files with 56 additions and 1,088 deletions.
13 changes: 0 additions & 13 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,6 @@ concurrency:
cancel-in-progress: true

jobs:
server-e2e-jobs:
name: Server (e2e-jobs)
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4
with:
submodules: 'recursive'

- name: Run e2e tests
run: make server-e2e-jobs

doc-tests:
name: Docs
runs-on: ubuntu-latest
Expand Down
3 changes: 0 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@ stage:
pull-stage:
docker compose -f ./docker/docker-compose.staging.yml pull

server-e2e-jobs:
docker compose -f ./server/e2e/docker-compose.server-e2e.yml up --renew-anon-volumes --abort-on-container-exit --exit-code-from immich-server --remove-orphans --build

.PHONY: e2e
e2e:
docker compose -f ./e2e/docker-compose.yml up --build -V --remove-orphans
Expand Down
23 changes: 16 additions & 7 deletions docs/docs/developer/testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,24 @@ Unit are run by calling `npm run test` from the `server` directory.

### End to end tests

The backend has two end-to-end test suites that can be called with the following two commands from the project root directory:
The e2e tests can be run by first starting up a test production environment via:

- `make server-e2e-api`
- `make server-e2e-jobs`
```bash
make e2e
```

#### API (e2e)
Once the test environment is running, the e2e tests can be run via:

The API e2e tests spin up a test database and execute http requests against the server, validating the expected response codes and functionality for API endpoints.
```bash
cd e2e/
npm test
```

#### Jobs (e2e)
The tests check various things including:

The Jobs e2e tests spin up a docker test environment where thumbnail generation, library scanning, and other _job_ workflows are validated.
- Authentication and authorization
- Query param, body, and url validation
- Response codes
- Thumbnail generation
- Metadata extraction
- Library scanning
39 changes: 2 additions & 37 deletions e2e/src/api/specs/library.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ describe('/library', () => {
beforeAll(async () => {
await utils.resetDatabase();
admin = await utils.adminSetup();
await utils.resetAdminConfig(admin.accessToken);
user = await utils.userSetup(admin.accessToken, userDto.user1);
library = await utils.createLibrary(admin.accessToken, { ownerId: admin.userId, type: LibraryType.External });
websocket = await utils.connectWebsocket(admin.accessToken);
Expand All @@ -36,7 +37,7 @@ describe('/library', () => {

afterAll(() => {
utils.disconnectWebsocket(websocket);
utils.deleteTempFolder();
utils.resetTempFolder();
});

beforeEach(() => {
Expand Down Expand Up @@ -816,40 +817,4 @@ describe('/library', () => {
expect(existsSync(`${testAssetDir}/temp/directoryB/assetB.png`)).toBe(true);
});
});

// describe('Watching', () => {
// beforeAll(async () => {
// const config = await getConfigDefaults({ headers: asBearerAuth(admin.accessToken) });
// await updateConfig(
// { systemConfigDto: { ...config, library: { ...config.library, watch: { enabled: true } } } },
// { headers: asBearerAuth(admin.accessToken) },
// );
// });

// afterAll(async () => {
// const defaultConfig = await getConfigDefaults({ headers: asBearerAuth(admin.accessToken) });
// await updateConfig({ systemConfigDto: defaultConfig }, { headers: asBearerAuth(admin.accessToken) });
// rmSync(`${testAssetDir}/temp/watch`, { recursive: true });
// });

// describe('Single import path', () => {
// let library: LibraryResponseDto;
// beforeEach(async () => {
// library = await utils.createLibrary(admin.accessToken, {
// ownerId: admin.userId,
// type: LibraryType.External,
// importPaths: [`${testAssetDirInternal}/temp`],
// });
// });

// it('should import a new file', async () => {
// utils.createImageFile(`${testAssetDir}/temp/watch/assetA.png`);

// await utils.waitForWebsocketEvent({ event: 'assetUpload', total: 1 });

// const { assets } = await utils.metadataSearch(admin.accessToken, { libraryId: library.id });
// expect(assets.count).toEqual(3);
// });
// });
// });
});
22 changes: 17 additions & 5 deletions e2e/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@ import {
getAllAssets,
getAllJobsStatus,
getAssetInfo,
getConfigDefaults,
login,
searchMetadata,
setAdminOnboarding,
signUpAdmin,
updateConfig,
validate,
} from '@immich/sdk';
import { BrowserContext } from '@playwright/test';
Expand Down Expand Up @@ -139,6 +141,7 @@ export const utils = {
'user_token',
'users',
'system_metadata',
'system_config',
];

const sql: string[] = [];
Expand All @@ -148,7 +151,12 @@ export const utils = {
}

for (const table of tables) {
sql.push(`DELETE FROM ${table} CASCADE;`);
if (table === 'system_metadata') {
// prevent reverse geocoder from being re-initialized
sql.push(`DELETE FROM "system_metadata" where "key" != 'reverse-geocoding-state';`);
} else {
sql.push(`DELETE FROM ${table} CASCADE;`);
}
}

await client.query(sql.join('\n'));
Expand Down Expand Up @@ -310,9 +318,7 @@ export const utils = {
if (!existsSync(dirname(path))) {
mkdirSync(dirname(path), { recursive: true });
}
if (!existsSync(path)) {
writeFileSync(path, makeRandomImage());
}
writeFileSync(path, makeRandomImage());
},

removeImageFile: (path: string) => {
Expand Down Expand Up @@ -407,8 +413,14 @@ export const utils = {
},
]),

deleteTempFolder: () => {
resetTempFolder: () => {
rmSync(`${testAssetDir}/temp`, { recursive: true, force: true });
mkdirSync(`${testAssetDir}/temp`, { recursive: true });
},

resetAdminConfig: async (accessToken: string) => {
const defaultConfig = await getConfigDefaults({ headers: asBearerAuth(accessToken) });
await updateConfig({ systemConfigDto: defaultConfig }, { headers: asBearerAuth(accessToken) });
},

isQueueEmpty: async (accessToken: string, queue: keyof AllJobStatusResponseDto) => {
Expand Down
10 changes: 0 additions & 10 deletions server/e2e/client/asset-api.ts

This file was deleted.

23 changes: 0 additions & 23 deletions server/e2e/client/auth-api.ts

This file was deleted.

9 changes: 0 additions & 9 deletions server/e2e/client/index.ts

This file was deleted.

33 changes: 0 additions & 33 deletions server/e2e/client/library-api.ts

This file was deleted.

33 changes: 0 additions & 33 deletions server/e2e/docker-compose.server-e2e.yml

This file was deleted.

17 changes: 0 additions & 17 deletions server/e2e/jobs/config/library-watcher-e2e-config.json

This file was deleted.

12 changes: 0 additions & 12 deletions server/e2e/jobs/immich-e2e-config.json

This file was deleted.

22 changes: 0 additions & 22 deletions server/e2e/jobs/jest-e2e.json

This file was deleted.

42 changes: 0 additions & 42 deletions server/e2e/jobs/setup.ts

This file was deleted.

Loading

0 comments on commit dba3656

Please sign in to comment.