Skip to content

Commit

Permalink
ai recommendation int test
Browse files Browse the repository at this point in the history
integration test that turns on the ai toggle and checks that something
is recommended
  • Loading branch information
hjwilli committed Apr 19, 2019
1 parent 803a02d commit b58de1d
Show file tree
Hide file tree
Showing 6 changed files with 121 additions and 5 deletions.
4 changes: 3 additions & 1 deletion docker-compose-int-test.yml
Expand Up @@ -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:
Expand Down
6 changes: 6 additions & 0 deletions tests/integration/jest/labApi.js
Expand Up @@ -14,13 +14,19 @@ 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');

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`);

103 changes: 103 additions & 0 deletions 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")
*/
});
});
6 changes: 3 additions & 3 deletions tests/integration/jest/runExperiment.test.ts
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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 = {
Expand Down Expand Up @@ -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 = {
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/jest/util/apiHelper.js
Expand Up @@ -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 {
Expand Down
5 changes: 5 additions & 0 deletions 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) => {
Expand Down

0 comments on commit b58de1d

Please sign in to comment.