-
Notifications
You must be signed in to change notification settings - Fork 26
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
Basic Testing for Discojs #697
base: develop
Are you sure you want to change the base?
Conversation
… equals are useless boilerplate for a short function (a variable should only be declared if it is used at least twice, except in very few exceptions that need excplicit justification
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for the contribution! some stuff to iron out, I hope that the remarks will help.
you didn't explicitly ask for a review but your PR wasn't in draft so I though I'll take a look
also, the CI failed with some lint error, you might want to look into it.
btw, the branch name is not following our guidelines, its format is $issue-$description-in-very-few-workd-$username
discojs/src/aggregator.spec.ts
Outdated
it("model correctly initialized", async () => { | ||
const aggregator = new Aggregator(); | ||
|
||
const model = mock(Model); | ||
|
||
aggregator.setModel(instance(model)); | ||
expect(aggregator.model).to.equal(instance(model)); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, no need to test for that, aggregator would need to be redone at some point and avoiding to have any reference to the task or the model will be the first thing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thank you. It's the first time I work on GitHub with PRs that are not made by cloning for a PR. Should I make a new branch from this branch for the PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure that I follow you: this is already a PR, you can added changes by pushing new commits to the same branch ("test_components") and it'll show up here.
discojs/src/aggregator.spec.ts
Outdated
@@ -1,6 +1,6 @@ | |||
import { expect } from "chai"; | |||
import { Map, Range, Set } from "immutable"; | |||
|
|||
import { mock, instance, when, anything } from 'ts-mockito'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hum, discojs is still using mocha/chai but if we want new features not present in theses, we will rather move to vitest (already used in the webapp & discojs-node) which provides mocking, parallel testing, good typescript support, …
that said, after the other comments, I don't think you'll even need "ts-mockito" anymore
@@ -20,10 +20,53 @@ AGGREGATORS.forEach(([name, Aggregator]) => | |||
describe(`${name} implements Aggregator contract`, () => { | |||
it("starts at round zero", () => { | |||
const aggregator = new Aggregator(); | |||
|
|||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that's not needed (and is being shown as very red in my git diff
).
we don't enforce a formatter yet but I'm all for slowly moving to prettier (that is, when you add changes, prettify it around, but not the whole file if you only changed a line). I'm hopeful that the transition will be smoother this way.
expect(aggregator.isFull()); | ||
}); | ||
|
||
it("is not full when created with more than no nodes and empty", () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it("is not full when created with more than no nodes and empty", () => { | |
it("is empty when without contributions", () => { |
|
||
|
||
|
||
it("is full when enough contributions", () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it("is full when enough contributions", () => { | |
it("is full with enough contributions", () => { |
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
too much whitespaces
expect(aggregator.round).to.equal(1); | ||
}); | ||
|
||
it("does not move forward with not enough contributions", async () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
double negation are hard on my brain. it also feels as a duplicate of the previous one. you can merge the two and check that it didn't advance with only two clients contributions but does with three.
expect(aggregator.round).to.equal(0); | ||
}); | ||
|
||
it("Adding at the wrong round does not count", () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reads more nicely. also, you can keep the test itself smaller by not having three clients but only one. less code == faster to understand => less bug.
it("Adding at the wrong round does not count", () => { | |
it("drops contributions for futur rounds", () => { |
@@ -11,7 +11,8 @@ | |||
"webapp" | |||
], | |||
"dependencies": { | |||
"immutable": "4" | |||
"immutable": "4", | |||
"ts-mockito": "^2.6.1" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the root package.json is hardly ever changed, especially for dev deps used in a single package. I use it for syncing version of dependencies that are needed across many packages.
please modify discojs/package.json if you want to add a package for discojs. (which you probably don't need as stated previously)
it('avg of weights with no operands throws an error', () => { | ||
assert.throws(() => aggregation.avg([])) | ||
}) | ||
|
||
it('sum of weights with no operands throws an error', () => { | ||
assert.throws(() => aggregation.sum([])) | ||
}) | ||
|
||
it('diff of weights with no operands throws an error', () => { | ||
assert.throws(() => aggregation.diff([])) | ||
}) | ||
|
||
it('avg of weights with different dimensions throws an error', () => { | ||
assert.throws(() => aggregation.avg([ | ||
[[3, -4], [9]], | ||
[[2, 13, 4], [0, 1]] | ||
])) | ||
}) | ||
|
||
it('sum of weights with different dimensions throws an error', () => { | ||
assert.throws(() => aggregation.sum([ | ||
[[3, -4], [9]], | ||
[[2, 13, 4], [0, 1]] | ||
])) | ||
}) | ||
|
||
it('diff of weights with different dimensions throws an error', () => { | ||
assert.throws(() => aggregation.diff([ | ||
[[3, -4], [9]], | ||
[[2, 13, 4], [0, 1]] | ||
])) | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is a bench test, you can simplify it by using a Set(…).forEach((op) => …)
while at it, should it fail? an addition without value can be zero, a multiplication can be one; why is this test needed?
it('avg of weights with no operands throws an error', () => { | |
assert.throws(() => aggregation.avg([])) | |
}) | |
it('sum of weights with no operands throws an error', () => { | |
assert.throws(() => aggregation.sum([])) | |
}) | |
it('diff of weights with no operands throws an error', () => { | |
assert.throws(() => aggregation.diff([])) | |
}) | |
it('avg of weights with different dimensions throws an error', () => { | |
assert.throws(() => aggregation.avg([ | |
[[3, -4], [9]], | |
[[2, 13, 4], [0, 1]] | |
])) | |
}) | |
it('sum of weights with different dimensions throws an error', () => { | |
assert.throws(() => aggregation.sum([ | |
[[3, -4], [9]], | |
[[2, 13, 4], [0, 1]] | |
])) | |
}) | |
it('diff of weights with different dimensions throws an error', () => { | |
assert.throws(() => aggregation.diff([ | |
[[3, -4], [9]], | |
[[2, 13, 4], [0, 1]] | |
])) | |
}) | |
Set.of(aggregation.avg, aggregation.sum, aggregation.diff).forEach((op) => { | |
it(`${op.name} of weights with no operands throws`, () => | |
expect(() => op([])).to.throw()); | |
it(`${op.name} of weights with different dimensions throws`, () => | |
expect(() => op([[[1, 2]], [[3, 4, 5]]])).to.throw()); | |
}); |
…rfect; there are some timeouts...
…g task, and check that connection fails for non existing task. Note: I need to figure out how to run the CI scripts before I commit. My code is unclean.
No description provided.