diff --git a/docker-compose-int-test.yml b/docker-compose-int-test.yml index 4864e72d0..6797d5661 100644 --- a/docker-compose-int-test.yml +++ b/docker-compose-int-test.yml @@ -31,7 +31,9 @@ services: - "443:443" - "5080:5080" environment: - - AI_AUTOSTART=0 + - AI_RECOMMENDER=random + - AI_NUMRECOMMEND=1 + - AI_AUTOSTART=1 - STARTUP_DATASET_PATH=/appsrc/data/datasets/test/test_mixed env_file: ./config/common.env depends_on: diff --git a/tests/integration/jest/labApi.js b/tests/integration/jest/labApi.js index bce87dff7..5d943a8fd 100644 --- a/tests/integration/jest/labApi.js +++ b/tests/integration/jest/labApi.js @@ -14,6 +14,7 @@ export const fetchDatasetMetafeatures = (id) => get(`http://lab:5080/api/v1/file export const fetchMachines = () => get('http://lab:5080/api/v1/machines'); export const fetchExperiments = () => get('http://lab:5080/api/userexperiments'); +export const fetchExperimentsParms = (parms) => post(`http://lab:5080/api/v1/experiments`, parms); export const fetchExperiment = (id) => get(`http://lab:5080/api/v1/experiments/${id}`); export const fetchAlgorithms = () => get('http://lab:5080/api/projects'); @@ -21,6 +22,11 @@ export const fetchAlgorithms = () => get('http://lab:5080/api/projects'); export const submitExperiment = (algorithm, params) => post(`http://lab:5080/api/v1/projects/${algorithm}/experiment`, params); +export const updateAiStatus = (datasetId, aiStatus) => + put(`http://lab:5080/api/userdatasets/${datasetId}/ai`, {'ai':aiStatus}); + +export const getAiStatus = (datasetId) => get(`http://lab:5080/api/userdatasets/${datasetId}/ai`) + export const fetchExperimentModel = (id) => get(`http://lab:5080/api/v1/experiments/${id}/model`); export const fetchExperimentScript = (id) => get(`http://lab:5080/api/v1/experiments/${id}/script`); diff --git a/tests/integration/jest/runAi.test.ts b/tests/integration/jest/runAi.test.ts new file mode 100644 index 000000000..e084a4d42 --- /dev/null +++ b/tests/integration/jest/runAi.test.ts @@ -0,0 +1,103 @@ +/** +* Run and experiment +* +*/ + +import * as labApi from './labApi'; +import * as machineApi from './machineApi'; +import * as dbBuilder from "./util/db"; +import * as util from "./util/testUtils"; + +/* +const db = dbBuilder.openDbConnection(); + + +afterAll(() => { + db.close(); +}); +*/ + +describe('ai', () => { + it('start ai for banana', async () => { + console.log('start ai') + + jest.setTimeout(util.JEST_TIMEOUT) + + let algoName = 'LogisticRegression' + let datasetName = 'banana' + + let newSuccessExpParms = {'date_start':Date.now(), '_status':'success'} + + //------------------- + // get dataset + var datasets = await labApi.fetchDatasets(); + expect(datasets.length).toBeGreaterThan(1); + var datasetId = datasets.find(function(element) {return element.name == datasetName;})._id; + expect(datasetId).toBeTruthy(); + + // get algorithm + var algorithms = await labApi.fetchAlgorithms(); + expect(algorithms.length).toBeGreaterThanOrEqual(util.MIN_EXPECTED_LAB_ALGO_COUNT); + var algoId = algorithms.find(function(element) {return element.name == algoName;})._id; + expect(algoId).toBeTruthy(); + + // make sure machine is free + var capRes = await machineApi.fetchCapacity(algoId) + expect(capRes.capacity).toEqual(1) + console.log("checked machine") + + // fetch previously run experiments + var prevExperiments = await labApi.fetchExperiments() + + // turn on ai + await labApi.updateAiStatus(datasetId, "requested") + + // wait for ai status to change + var dataset = await labApi.fetchDataset(datasetId) + console.log("dataset[0].ai: ", dataset[0].ai) + + var count = 0 + console.log("starting timeout...") + while (dataset[0].ai === ('requested') && count < 10) { + util.delay(10000) + count = count + 1 + dataset = await labApi.fetchDataset(datasetId) + console.log("dataset[0].ai, count (" + count + "): ", dataset[0].ai) + } + console.log("finished timeout...") + console.log("dataset[0].ai: ", dataset[0].ai) + + // check ai status + expect(dataset[0].ai).toBeTruthy() + expect(dataset[0].ai).toEqual('finished') + + // check for new experiments + var allExperiments = await labApi.fetchExperiments() + expect(allExperiments.length).toEqual(prevExperiments.length + util.NUM_AI_RECS) + console.log("checked new experiment count") + + // wait for experiments to complete + console.log("waiting for experiments to finish") + var experiments = await labApi.fetchExperimentsParms(newSuccessExpParms) + console.log("new success experiments:", experiments) + + var count = 0 + console.log("starting timeout...") + while (!experiments && count < 10) { + util.delay(10000) + count = count + 1 + experiments = await labApi.fetchExperimentsParms(newSuccessExpParms) + console.log("new success experiments, count (" + count + "): ", experiments) + } + console.log("finished timeout...") + + expect(experiments).toBeTruthy() + + /* + // make sure machine is free + var capRes = await machineApi.fetchCapacity(algoId) + expect(capRes.capacity).toEqual(1) + console.log("checked machine") + */ + }); +}); \ No newline at end of file diff --git a/tests/integration/jest/runExperiment.test.ts b/tests/integration/jest/runExperiment.test.ts index 579c1f729..7711d75fa 100644 --- a/tests/integration/jest/runExperiment.test.ts +++ b/tests/integration/jest/runExperiment.test.ts @@ -22,7 +22,7 @@ describe('run experiment', () => { it('run decisionTree experiment on banana', async () => { console.log('run decisionTree experiment on banana') - jest.setTimeout(15000) + jest.setTimeout(util.JEST_TIMEOUT) /* let algoName = 'DecisionTreeClassifier' let algoParms = { @@ -110,7 +110,7 @@ describe('run experiment', () => { it('run decisionTree experiment with invalid parms on banana', async () => { console.log('run decisionTree experiment with invalid parms on banana') - jest.setTimeout(15000) + jest.setTimeout(util.JEST_TIMEOUT) let algoName = 'LogisticRegression' let algoParms = { @@ -190,7 +190,7 @@ describe('run experiment', () => { it.skip('start and then kill experiment', async () => { console.log('start and then kill experiment') - jest.setTimeout(20000) + jest.setTimeout(util.JEST_TIMEOUT) let algoName = 'SVC' let algoParms = { diff --git a/tests/integration/jest/util/apiHelper.js b/tests/integration/jest/util/apiHelper.js index f93379b29..99736e926 100644 --- a/tests/integration/jest/util/apiHelper.js +++ b/tests/integration/jest/util/apiHelper.js @@ -104,7 +104,7 @@ export const putFormData = (route, form) => { function checkStatus(response) { if (response.status >= 400) { //console.log(`error: ${response.error}`) - var error = new Error(`${response.status}: ${response.statusText}`); + var error = new Error(`${response.status}: ${response.statusText} : ${response.url}`); error.response = response; throw error; } else { diff --git a/tests/integration/jest/util/testUtils.js b/tests/integration/jest/util/testUtils.js index 315d74830..72070e00b 100644 --- a/tests/integration/jest/util/testUtils.js +++ b/tests/integration/jest/util/testUtils.js @@ -1,10 +1,15 @@ +var os = require("os"); + export const EXPECTED_MACHINE_ALGO_COUNT = 6; // number of algorithms registered with a machine instance export const MIN_EXPECTED_LAB_ALGO_COUNT = 10; // min number of algorithms registered with in the server export const MIN_EXPECTED_DATASET_COUNT = 4; // min number of datasets registered with the lab server, more may be added w. tests export const DATASET_PATH = '/appsrc/data/datasets/test/integration' // datasets for testing +export const NUM_AI_RECS = 1 +//export const NUM_AI_RECS = os.environ['AI_NUMRECOMMEND'] +export const JEST_TIMEOUT = 30000 // hacky delay export const delay = (ms) => {