From 8a66e8bd983bd5c73d8c787abcb7ad3f1dcc9c12 Mon Sep 17 00:00:00 2001 From: "A. Jard" Date: Fri, 3 Jan 2025 08:40:18 +0100 Subject: [PATCH] [CI] Add a test-result folder in backend and upload to JFrog to help debug stream count issues. --- .drone.yml | 2 ++ .../tests/03-streams/00-Raw/raw-test.js | 2 ++ .../tests/03-streams/01-Live/live-test.js | 2 ++ .../opencti-graphql/tests/utils/testOutput.ts | 17 +++++++++++++++++ 4 files changed, 23 insertions(+) create mode 100644 opencti-platform/opencti-graphql/tests/utils/testOutput.ts diff --git a/.drone.yml b/.drone.yml index 3307abf5880d..fea40d96bfb2 100644 --- a/.drone.yml +++ b/.drone.yml @@ -124,6 +124,8 @@ steps: # Archive and upload each artefact that we need - tar -czvf frontend-test-results-$DRONE_BUILD_NUMBER.tar.gz opencti-platform/opencti-front/test-results - jf rt u frontend-test-results-$DRONE_BUILD_NUMBER.tar.gz $JFROG_REPOSITORY --build-name=$JFROG_BUILD_NAME --build-number=$DRONE_BUILD_NUMBER --url=$JFROG_URL --access-token=$JFROG_TOKEN + - tar -czvf backend-test-results-$DRONE_BUILD_NUMBER.tar.gz opencti-platform/opencti-graphql/test-results + - jf rt u backend-test-results-$DRONE_BUILD_NUMBER.tar.gz $JFROG_REPOSITORY --build-name=$JFROG_BUILD_NAME --build-number=$DRONE_BUILD_NUMBER --url=$JFROG_URL --access-token=$JFROG_TOKEN # Next line should be done only once at the end: it's recording and gathering build info - jf rt bp $JFROG_BUILD_NAME $DRONE_BUILD_NUMBER --url=$JFROG_URL --access-token=$JFROG_TOKEN --build-url=$DRONE_BUILD_LINK # Cleaning up old build in JFrog diff --git a/opencti-platform/opencti-graphql/tests/03-streams/00-Raw/raw-test.js b/opencti-platform/opencti-graphql/tests/03-streams/00-Raw/raw-test.js index 0151c3e0ec1d..2ed2733a6177 100644 --- a/opencti-platform/opencti-graphql/tests/03-streams/00-Raw/raw-test.js +++ b/opencti-platform/opencti-graphql/tests/03-streams/00-Raw/raw-test.js @@ -5,6 +5,7 @@ import { FIVE_MINUTES, RAW_EVENTS_SIZE } from '../../utils/testQuery'; import { checkStreamData, checkStreamGenericContent, fetchStreamEvents, } from '../../utils/testStream'; import { PORT } from '../../../src/config/conf'; import { EVENT_TYPE_CREATE, EVENT_TYPE_DELETE, EVENT_TYPE_MERGE, EVENT_TYPE_UPDATE } from '../../../src/database/utils'; +import { writeTestDataToFile } from '../../utils/testOutput'; describe('Raw streams tests', () => { // We need to check the event format to be sure that everything is setup correctly @@ -13,6 +14,7 @@ describe('Raw streams tests', () => { async () => { // Read all events from the beginning. const events = await fetchStreamEvents(`http://localhost:${PORT}/stream`, { from: '0' }); + writeTestDataToFile(JSON.stringify(events), 'raw-test-all-event.json'); // Check the number of events // 01 - CHECK CREATE EVENTS. const createEvents = events.filter((e) => e.type === EVENT_TYPE_CREATE); diff --git a/opencti-platform/opencti-graphql/tests/03-streams/01-Live/live-test.js b/opencti-platform/opencti-graphql/tests/03-streams/01-Live/live-test.js index afefd8f53a3b..362d176ea511 100644 --- a/opencti-platform/opencti-graphql/tests/03-streams/01-Live/live-test.js +++ b/opencti-platform/opencti-graphql/tests/03-streams/01-Live/live-test.js @@ -8,6 +8,7 @@ import { convertStoreToStix, convertTypeToStixType } from '../../../src/database import { utcDate } from '../../../src/utils/format'; import { PORT } from '../../../src/config/conf'; import { READ_DATA_INDICES } from '../../../src/database/utils'; +import { writeTestDataToFile } from '../../utils/testOutput'; describe('Live streams tests', () => { const getElementsCounting = async () => { @@ -49,6 +50,7 @@ describe('Live streams tests', () => { const stixReport = convertStoreToStix(report); const now = utcDate().toISOString(); const events = await fetchStreamEvents(`http://localhost:${PORT}/stream/live?from=0&recover=${now}`); + writeTestDataToFile(JSON.stringify(events), 'live-test-all-event.json'); expect(events.length).toBe(SYNC_LIVE_EVENTS_SIZE); await checkResultCounting(events); for (let index = 0; index < events.length; index += 1) { diff --git a/opencti-platform/opencti-graphql/tests/utils/testOutput.ts b/opencti-platform/opencti-graphql/tests/utils/testOutput.ts new file mode 100644 index 000000000000..c2343b7c1cbb --- /dev/null +++ b/opencti-platform/opencti-graphql/tests/utils/testOutput.ts @@ -0,0 +1,17 @@ +import fs from 'node:fs'; +import { join } from 'node:path'; + +const TEST_OUTPUT_FOLDER = 'test-results'; + +/** + * Write content to a folder that will be archived at the end of test in CI. + * @param fileContent + * @param filename + */ +export const writeTestDataToFile = (fileContent: string, filename: string) => { + if (!fs.existsSync(TEST_OUTPUT_FOLDER)) { + fs.mkdirSync(TEST_OUTPUT_FOLDER, { recursive: true }); + } + const filePath = join(TEST_OUTPUT_FOLDER, filename); + fs.writeFileSync(filePath, fileContent, {}); +};