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

Refactor testApi.mjs #1055

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open

Refactor testApi.mjs #1055

wants to merge 8 commits into from

Conversation

zaneenders
Copy link
Collaborator

This is essentially a new testApi.mjs file refactored to compose functions like simulateOdysseyCall.

@zaneenders zaneenders marked this pull request as ready for review November 16, 2024 18:08
Copy link
Contributor

@pavpanchekha pavpanchekha left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is every damn method got duplicate code for the async and non-async case?

src/api/demo.rkt Show resolved Hide resolved
infra/testApi.mjs Outdated Show resolved Hide resolved
infra/testApi.mjs Outdated Show resolved Hide resolved
infra/testApi.mjs Outdated Show resolved Hide resolved
infra/testApi.mjs Outdated Show resolved Hide resolved
infra/testApi.mjs Outdated Show resolved Hide resolved
infra/testApi.mjs Outdated Show resolved Hide resolved
infra/testApi.mjs Outdated Show resolved Hide resolved
infra/testApi.mjs Show resolved Hide resolved
infra/testApi.mjs Outdated Show resolved Hide resolved
Copy link
Contributor

@pavpanchekha pavpanchekha left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Look man, the changes are probably improvements I guess, but doesn't the file still look like a mess afterwards? You still can't read the file and know what the actual policy is, the rules that it's trying to enforce.

formula: fpcore, sample: p_context
}), async_huh);
assertIdAndPath(analyze_json);
checkFelids(analyze_json, ['command', 'points', 'job', 'path']);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
checkFelids(analyze_json, ['command', 'points', 'job', 'path']);
checkFeilds(analyze_json, ['command', 'points', 'job', 'path']);

const check_missing_job = await fetchAndCheckRSPHeaders(`/check-status/42069`, { method: 'GET' }, CHECK_CORS)
assert.equal(check_missing_job.status, 202);

// MARK: UP
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this // MARK: UP do?

const analyze_json = await getJSONFor('analyze', 'POST', JSON.stringify({
formula: fpcore, sample: p_context
}), async_huh);
assertIdAndPath(analyze_json);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you call this every time you call getJSONFor, except for the mathjs translator. Move into getJSONFor?

Comment on lines +89 to +90
const exacts1 = await callExacts(FPCoreFormula2, eval_sample, true);
const exacts2 = await callExacts(FPCoreFormula2, eval_sample, false);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think every test is repeated twice, once in async mode and once not. Maybe build that into getJSONFor instead of having to do it manually?


// MARK: Sample
async function callSample(fpcore, async_huh) {
var sample_json = await getJSONFor('sample', 'POST', JSON.stringify({ formula: fpcore, seed: 5 }), async_huh);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I can tell, getJSONFor is always called with a method of POST and the body is always JSON. Can we move that into getJSONFor?

Comment on lines +258 to +259
const timelineRSP = await fetchAndCheckRSPHeaders(`/timeline/${job_iD}`, { method: 'GET' }, CHECK_CORS);
assert.equal(timelineRSP.status, 201);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we fetching the timeline here just to check that it was a valid job id? This is a weird test.

const improveResponse = await fetch(makeEndpoint(`/improve?formula=${encodeURIComponent(FPCoreFormula2)}`), { method: 'GET' })
assert.equal(improveResponse.status, 200);
let redirect = improveResponse.url.split("/");
const job_iD = redirect[3].split(".")[0];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the super weird capitalization in job_iD?


// improve-start endpoint
const URIencodedBody = "formula=" + encodeURIComponent(FPCoreFormula)
const startResponse = await fetch(makeEndpoint("/api/start/improve"), {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do all the other tests use a callXXX function but this one is fetch(makeEndpoint(...))? Why not at least wrap the fetch stuff so we wouldn't need to manually write makeEndpoint? And maybe the method, headers, etc? Maybe call encodeURIComponent if that's important?

Comment on lines +282 to +286
while (checkStatus.status != 201 && counter < cap) {
counter += 1
checkStatus = await fetch(makeEndpoint(improveResultPath), { method: 'GET' })
await new Promise(r => setTimeout(r, 100)); // ms
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess it's fine but isn't this a for loop with an early exit? Also I notice that even when the status is successful you still wait for 100ms before exiting.

Comment on lines -353 to +354
(response/full 201
(response/full 200
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Look, I guess whatever, but in this case I think a 201 does seem more appropriate? Since it doesn't include the body?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants