Skip to content

Commit

Permalink
Adding extra checks to ensure the services include the algorithm
Browse files Browse the repository at this point in the history
  • Loading branch information
jamiehewitt15 committed Jul 4, 2024
1 parent 65da101 commit 095cfcf
Showing 1 changed file with 97 additions and 17 deletions.
114 changes: 97 additions & 17 deletions test/c2d.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { exec } from "child_process";
import path from "path";
import fs from "fs";

const sleep = ms => new Promise(resolve => setTimeout(resolve, ms));

Check failure on line 6 in test/c2d.test.ts

View workflow job for this annotation

GitHub Actions / lint

'sleep' is assigned a value but never used

describe("C2D Tests", function() {
this.timeout(60000); // Set a longer timeout to allow the command to execute

Expand Down Expand Up @@ -86,8 +88,10 @@ describe("C2D Tests", function() {
}
});
});


it("should get DDO using 'npm run cli getDDO' for compute dataset", function(done) {
it("should get DDO using 'npm run cli getDDO' for compute dataset", async function(done) {

exec(`npm run cli getDDO ${computeDatasetDid}`, { cwd: projectRoot }, (error, stdout) => {
expect(stdout).to.contain(`${computeDatasetDid}`);
expect(stdout).to.contain("https://w3id.org/did/v1");
Expand All @@ -98,44 +102,120 @@ describe("C2D Tests", function() {

it("should get DDO using 'npm run cli getDDO' for JS algorithm", function(done) {
exec(`npm run cli getDDO ${jsAlgoDid}`, { cwd: projectRoot }, (error, stdout) => {
console.log('stdout', stdout)
expect(stdout).to.contain(`${jsAlgoDid}`);
expect(stdout).to.contain("https://w3id.org/did/v1");
expect(stdout).to.contain("Datatoken");
expect(stdout).to.contain("algorithm");
expect(stdout).to.contain("node $ALGO");
expect(stdout).to.contain("sha256:1155995dda741e93afe4b1c6ced2d01734a6ec69865cc0997daf1f4db7259a36");
done()
});
});

it("should get DDO using 'npm run cli getDDO' for python algorithm", function(done) {
exec(`npm run cli getDDO ${pythonAlgoDid}`, { cwd: projectRoot }, (error, stdout) => {
console.log('stdout', stdout)
expect(stdout).to.contain(`${pythonAlgoDid}`);
expect(stdout).to.contain("https://w3id.org/did/v1");
expect(stdout).to.contain("Datatoken");
expect(stdout).to.contain("algorithm");
expect(stdout).to.contain("python $ALGO");
expect(stdout).to.contain("sha256:8221d20c1c16491d7d56b9657ea09082c0ee4a8ab1a6621fa720da58b09580e4");
done()
});
});

it("should allow Python algorithm to run on the compute dataset", function(done) {
exec(`npm run cli allowAlgo ${computeDatasetDid} ${pythonAlgoDid}`, { cwd: projectRoot }, (error, stdout) => {
console.log('running: ', `npm run cli allowAlgo ${computeDatasetDid} ${pythonAlgoDid}`)
console.log("stdout", stdout)
expect(stdout).to.contain("Successfully updated asset metadata:");
done()
});
});

it("should start compute job with Python algorithm running on the compute dataset", function(done) {
this.timeout(60000);
// it("should start compute job with Python algorithm running on the compute dataset", function(done) {
// this.timeout(60000);
// const computeDatasetArray = JSON.stringify([computeDatasetDid]);
// exec(`npm run cli startCompute ${computeDatasetArray} ${pythonAlgoDid} 0`, { cwd: projectRoot }, (error, stdout) => {
// console.log('Running: ', `npm run cli startCompute ${computeDatasetArray} ${pythonAlgoDid} 0`);
// console.log("stdout:", stdout);
// if (error) {
// console.error("Error:", error);
// return done(error);
// }

// try {
// expect(stdout).to.contain("Starting compute job using provider");
// expect(stdout).to.contain("Ordering algorithm");
// expect(stdout).to.contain(pythonAlgoDid);
// expect(stdout).to.contain("Ordering asset with DID");
// expect(stdout).to.contain(computeDatasetDid);
// expect(stdout).to.contain("Starting compute job on");
// expect(stdout).to.contain("Consumer");
// expect(stdout).to.contain("JobID");
// expect(stdout).to.contain("Agreement ID");
// done();
// } catch (assertionError) {
// done(assertionError);
// }
// });
// });


// it("should start compute job with Python algorithm running on the compute dataset", function(done) {
// this.timeout(120000);
// // (async () => {
// // console.log('Waiting for 10 seconds before starting compute job');
// // await new Promise(resolve => setTimeout(resolve, 25000)); // wait 5 secondds
// // console.log('FInished waiting. Starting compute job');
// // })();
// const command = `npm run cli startCompute [${computeDatasetDid}] ${pythonAlgoDid} 0`;
// exec(command, { cwd: projectRoot }, (error, stdout) => {
// console.log('Running: ', command);
// console.log("stdout:", stdout);
// if (error) {
// console.error("Error:", error);
// return done(error);
// }

// try {
// expect(stdout).to.contain("Starting compute job using provider");
// expect(stdout).to.contain("Ordering algorithm");
// expect(stdout).to.contain(pythonAlgoDid);
// expect(stdout).to.contain("Ordering asset with DID");
// expect(stdout).to.contain(computeDatasetDid);
// expect(stdout).to.contain("Starting compute job on");
// expect(stdout).to.contain("Consumer");
// expect(stdout).to.contain("JobID");
// expect(stdout).to.contain("Agreement ID");
// done();
// } catch (assertionError) {
// done(assertionError);
// }
// });
// });


// it("should start compute job with Python algorithm running on the compute dataset", function(done) {
// this.timeout(120000)
// const computeDatasetArray = JSON.stringify([computeDatasetDid]);
// exec(`npm run cli startCompute ${computeDatasetArray} ${pythonAlgoDid} 0`, { cwd: projectRoot }, (error, stdout) => {
// console.log('stdout', stdout)
// expect(stdout).to.contain("Starting compute job using provider");
// expect(stdout).to.contain("Ordering algorithm");
// expect(stdout).to.contain(pythonAlgoDid);
// expect(stdout).to.contain("Ordering asset with DID");
// expect(stdout).to.contain(computeDatasetDid);
// expect(stdout).to.contain("Starting compute job on");
// expect(stdout).to.contain("Consumer");
// expect(stdout).to.contain("JobID");
// expect(stdout).to.contain("Agreement ID");
// done()
// });
// });

it("start compute job with JS algorithm should fail as it has not been allowed", function(done) {
const computeDatasetArray = JSON.stringify([computeDatasetDid]);
exec(`npm run cli startCompute ${computeDatasetArray} ${pythonAlgoDid} 0`, { cwd: projectRoot }, (error, stdout) => {
expect(stdout).to.contain("Starting compute job using provider");
expect(stdout).to.contain("Ordering algorithm");
expect(stdout).to.contain(pythonAlgoDid);
expect(stdout).to.contain("Ordering asset with DID");
expect(stdout).to.contain(computeDatasetDid);
expect(stdout).to.contain("Starting compute job on");
expect(stdout).to.contain("Consumer");
expect(stdout).to.contain("JobID");
expect(stdout).to.contain("Agreement ID");
exec(`npm run cli startCompute ${computeDatasetArray} ${jsAlgoDid} 0`, { cwd: projectRoot }, (error, stdout) => {
console.log('stdout', stdout)
done()
});
});
Expand Down

0 comments on commit 095cfcf

Please sign in to comment.