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

Properly remove on_delete and on_update callbacks that fail. #822

Merged
merged 3 commits into from
Nov 24, 2019
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -154,5 +154,6 @@ python/cpp
python/perspective/perspective_python.egg-info
python/perspective/perspective/tests/table/psp_test
python/perspective/perspective/node/assets/*
/__pycache__
docs/static/js/logo.js
docs/static/js/logo.js.map
5 changes: 3 additions & 2 deletions packages/perspective/src/js/api/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,9 @@ export class Server {

this.post(result);
} catch (e) {
console.error("Removing callback after failed on_update() (presumably due to closed connection)");
obj["remove_update"](callback);
console.error(`Removing failed callback to \`${msg.method}()\` (presumably due to failed connection)`);
const remove_method = msg.method.substring(3);
obj[`remove_${remove_method}`](callback);
}
};
if (msg.callback_id) {
Expand Down
26 changes: 26 additions & 0 deletions packages/perspective/test/js/delete.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,5 +76,31 @@ module.exports = perspective => {

await table.delete();
});

it("properly removes a failed delete callback on a table", async function(done) {
const table = perspective.table([{x: 1}]);

// when a callback throws, it should delete that callback
table.on_delete(() => {
throw new Error("something went wrong!");
});

table.delete();
done();
});

it("properly removes a failed delete callback on a view", async function(done) {
const table = perspective.table([{x: 1}]);
const view = table.view();

// when a callback throws, it should delete that callback
view.on_delete(() => {
throw new Error("something went wrong!");
});

view.delete();
table.delete();
done();
});
});
};
33 changes: 33 additions & 0 deletions packages/perspective/test/js/updates.js
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,39 @@ module.exports = perspective => {
);
table1.update(data);
});

it("properly removes a failed update callback on a table", async function(done) {
const table = perspective.table({x: "integer"});
const view = table.view();
let size = await table.size();
let counter = 0;

// when a callback throws, it should delete that callback
view.on_update(() => {
counter++;
throw new Error("something went wrong!");
});

view.on_update(async () => {
// failed callback gets removed; non-failing callback gets called
let sz = await table.size();
expect(counter).toEqual(1);
expect(sz).toEqual(size++);
});

table.update([{x: 1}]);
table.update([{x: 2}]);
table.update([{x: 3}]);

const view2 = table.view(); // create a new view to make sure we process every update transacation.
const final_size = await table.size();
expect(final_size).toEqual(3);

view2.delete();
view.delete();
table.delete();
done();
});
});

describe("Limit", function() {
Expand Down