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

Abort the previous bake when attempting the next autobake #1786

Merged
merged 3 commits into from
Apr 15, 2024
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
7 changes: 6 additions & 1 deletion src/web/App.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,12 @@ class App {
// has completed.
if (this.autoBakePause) return false;

if (this.autoBake_ && !this.baking) {
if (this.baking) {
Copy link
Member

Choose a reason for hiding this comment

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

I do intend to review this properly in time, I just think this PR likely needs an extensive amount of testing to make sure it doesn't break any other aspects of the service.

In particular, I'm struggling to work out why the original implementation explicitly excluded autobaking when an existing value was being computed.

As well as that, I'm worried there's a race case somewhere here. Cancelling a bake in a worker looks asynchronous, as far as I can tell.

I should have more time tomorrow night to look into this, although I generally have more time for this project over the weekends.

this.manager.worker.cancelBakeForAutoBake();
this.baking = false;
}

if (this.autoBake_) {
Copy link
Member

Choose a reason for hiding this comment

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

I wonder why this variable alone ends in a _.

log.debug("Auto-baking");
this.manager.worker.bakeInputs({
nums: [this.manager.tabs.getActiveTab("input")],
Expand Down
22 changes: 22 additions & 0 deletions src/web/waiters/WorkerWaiter.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,28 @@ class WorkerWaiter {
};
}

/**
* Cancels the current bake making it possible to autobake again
*/
cancelBakeForAutoBake() {
if (this.totalOutputs > 1) {
this.cancelBake();
} else {
// In this case the UI changes can be skipped

for (let i = this.chefWorkers.length - 1; i >= 0; i--) {
if (this.chefWorkers[i].active) {
this.removeChefWorker(this.chefWorkers[i]);
}
}

this.inputs = [];
this.inputNums = [];
this.totalOutputs = 0;
this.loadingOutputs = 0;
}
}

/**
* Cancels the current bake by terminating and removing all ChefWorkers
*
Expand Down
41 changes: 41 additions & 0 deletions tests/browser/01_io.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,33 @@ module.exports = {
browser.expect.element("#output-text .cm-status-bar .eol-value").text.to.equal("LF");
},

"Autobaking the latest input": browser => {
// Use the sleep recipe to simulate a long running task
utils.loadRecipe(browser, "Sleep", "input", [2000]);

browser.waitForElementVisible("#stale-indicator");

// Enable previously disabled autobake
browser.click("#auto-bake-label");

browser.sendKeys("#input-text .cm-content", "1");

browser.pause(500);

// Make another change while the previous input is being baked
browser.sendKeys("#input-text .cm-content", "2");

browser
.waitForElementNotVisible("#stale-indicator")
.waitForElementNotVisible("#output-loader");

// Ensure we got the latest input baked
utils.expectOutput(browser, "input12");

// Turn autobake off again
browser.click("#auto-bake-label");
},

"Special content": browser => {
/* Special characters are rendered correctly */
utils.setInput(browser, SPECIAL_CHARS, false);
Expand Down Expand Up @@ -641,6 +668,20 @@ module.exports = {
},

"Loading from URL": browser => {
utils.clear(browser);

/* Side panel displays correct info */
utils.uploadFile(browser, "files/TowelDay.jpeg");

browser
.waitForElementVisible("#input-text .cm-file-details")
.waitForElementVisible("#input-text .cm-file-details .file-details-toggle-shown")
.waitForElementVisible("#input-text .cm-file-details .file-details-thumbnail")
.waitForElementVisible("#input-text .cm-file-details .file-details-name")
.waitForElementVisible("#input-text .cm-file-details .file-details-size")
.waitForElementVisible("#input-text .cm-file-details .file-details-type")
.waitForElementVisible("#input-text .cm-file-details .file-details-loaded");

/* Complex deep link populates the input correctly (encoding, eol, input) */
browser
.urlHash("recipe=To_Base64('A-Za-z0-9%2B/%3D')&input=VGhlIHNoaXBzIGh1bmcgaW4gdGhlIHNreSBpbiBtdWNoIHRoZSBzYW1lIHdheSB0aGF0IGJyaWNrcyBkb24ndC4M&ienc=21866&oenc=1201&ieol=FF&oeol=PS")
Expand Down
Loading