Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delete datasets bug fixes and integration test #623

Merged
merged 3 commits into from
Oct 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
# Leave this set to 0 on the GitHub repo so the unit and
# integration tests do not need to have wheels (until we
# find a convenient way to use wheels on GitHub)
TAG=0.20
TAG=0.21a0
USE_WHEELS=1
10 changes: 7 additions & 3 deletions lab/lab.js
Original file line number Diff line number Diff line change
Expand Up @@ -640,8 +640,10 @@ app.delete('/api/v1/datasets/:id', async (req, res, next) => {
return res.status(404).send({ message: 'dataset ' + req.params.id + ' not found'});
}

if (dataset.ai && (dataset.ai.status == recommenderStatus.RUNNING || dataset.ai.status == recommenderStatus.INITIALIZING)) {
return res.status(409).send({message: 'cannot delete dataset, recommender running'});
// if (dataset.ai && (dataset.ai.status == recommenderStatus.RUNNING || dataset.ai.status == recommenderStatus.INITIALIZING)) {
if (dataset.ai && ['on', 'requested'].some(status => dataset.ai.status === status)) {
console.log('cannot delete dataset, AI is enabled');
return res.status(409).send({message: 'cannot delete dataset, AI is enabled'});
}

const dataset_file_id = db.toObjectID(dataset.files[0]._id);
Expand All @@ -654,9 +656,11 @@ app.delete('/api/v1/datasets/:id', async (req, res, next) => {
]}

let experiments = await db.experiments.find(query).toArrayAsync();
let runningExp = experiments.find(exp => exp._status == 'running');
console.log(experiments);
let runningExp = experiments.find(exp => ['running', 'pending', 'suggested'].some(status => exp._status === status));

if (runningExp) {
console.log('cannot delete dataset, experiments running');
return res.status(409).send({message: 'cannot delete dataset, experiments running'});
}

Expand Down
67 changes: 67 additions & 0 deletions tests/integration/jest/machineApi.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,73 @@ describe('machine', () => {
expect(experimentResult._status).toEqual('success')
})

it('Test that a dataset cannot be deleted while running experiments', async () => {
// submit experiment, reuse dataset_result from previous test
let dataset_id = dataset_result.dataset_id;
let algoName = 'LogisticRegression'
let algoParams = {
"penalty": "l1",
"C": 1.0,
"dual": false,
"dataset": dataset_id
};
// get algorithms
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();

// submit a simple experiment
try {
var submitResult = await labApi.submitExperiment(algoId, algoParams);
} catch (e) {
console.log("submit experiment exception")
var json = await e.response.json();
expect(json).toBeFalsy();
expect(e).toBeFalsy();
}

expect(submitResult).toBeTruthy();

// expect that the experiment started running
var experimentResult = await labApi.fetchExperiment(submitResult._id)
//console.log("experimentResults: ", experimentResults)
expect(experimentResult._status).toBeTruthy()
expect(experimentResult._status).toEqual('running')

// delete dataset
let delete_dataset_result
try {
delete_dataset_result = await labApi.deleteDataset(dataset_id);
} catch (e) {
console.log('delete_dataset_result exception', e);
var json = await e.response.json()
expect(json).toBeTruthy()
expect(e.response.status).toEqual(409);
}

expect(delete_dataset_result).toBeFalsy();

// check that the experiment continued running and finished successfully
// wait for the experiment to finish running, probably a better way to do this then delay...
var count = 0
console.log("starting timeout...")
// while (experimentResult._status === ('running') && count < 10) {
while (experimentResult._status === ('running') && count < 30) {
util.delay(10000)
count = count + 1
experimentResult = await labApi.fetchExperiment(experimentResult._id)
console.log("experimentResult._status, count (" + count + "): ", experimentResult._status)
}
console.log("finished timeout...")

// check that the expected results are there
//console.log("experimentResult: ", experimentResult)
expect(experimentResult._status).toBeTruthy()
expect(experimentResult._status).toEqual('success')

})

it('Test the package install API endpoint with good package.', async () => {
var labCodeInstall = await labApi.postPackageInstall({ command: 'install', packages: ['numpy'] })
expect(labCodeInstall.exec_results.code).toEqual(0)
Expand Down
Loading