Skip to content
This repository has been archived by the owner on Dec 16, 2021. It is now read-only.

[DD-140] Introduce one more abstraction layer on top of helpers with mocha logic (hooks, timeouts) #85

Merged
merged 15 commits into from
May 15, 2018

Conversation

dreyacosta
Copy link
Contributor

@@ -32,6 +32,8 @@ async function spawnAndPromisifyIpfs() {

ipfsd.stop = util.promisify(ipfsd.stop).bind(ipfsd);
ipfsd.cleanup = util.promisify(ipfsd.cleanup).bind(ipfsd);
ipfsd.api.clean = ipfsd.cleanup;
ipfsd.api.remove = ipfsd.stop;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think we should review IPFS helper to follow the same interface as the other ones. Probably we should have an IPFSInstance.

Should we create an issue for this?

Copy link
Member

Choose a reason for hiding this comment

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

Don't like the idea to mutate API object. Let's use a plain object for instance temporary?

return {
   getApi() {
      return ipfsd.api;
   },
   remove: ipfsd.stop,
   clean: ipfsd.cleanup,
};

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I also prefer this approach. I didn't follow it at first because I don't want to modify the clients since we are returning ipfsd.api.

https://github.com/dashevo/dashdrive/blob/140-mocha-layer/lib/test/services/IPFS/startIPFSInstance.js#L66

clean: async function clean() {
await callInParallel(instance, 'clean');
},
remove: async function clean() {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This one needs a review too. We should follow the same interface (clean, remove) for all the startServiceInstance.

Right now this works, so, I'd say create a new issue.

@dreyacosta dreyacosta requested a review from shumkov May 14, 2018 19:59
@@ -32,6 +32,8 @@ async function spawnAndPromisifyIpfs() {

ipfsd.stop = util.promisify(ipfsd.stop).bind(ipfsd);
ipfsd.cleanup = util.promisify(ipfsd.cleanup).bind(ipfsd);
ipfsd.api.clean = ipfsd.cleanup;
ipfsd.api.remove = ipfsd.stop;
Copy link
Member

Choose a reason for hiding this comment

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

Don't like the idea to mutate API object. Let's use a plain object for instance temporary?

return {
   getApi() {
      return ipfsd.api;
   },
   remove: ipfsd.stop,
   clean: ipfsd.cleanup,
};

* @returns {Promise<DockerInstance>}
*/
async clean() {
return this;
Copy link
Member

Choose a reason for hiding this comment

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

Do you want to support chained interface for all class methods or just for this? Do we really need it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well, in reality, we just want a clean method for all DockerInstance. It could be an empty method to avoid breaking startHelperWithMochaHooksFactory.

https://github.com/dashevo/dashdrive/blob/140-mocha-layer/lib/test/services/mocha/startHelperWithMochaHooksFactory.js#L40

Copy link
Member

Choose a reason for hiding this comment

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

Yeah... let's keep it empty for a while.

before(async function before() {
this.timeout(25000);
const ipfsApi = await startIPFSInstance();
startIPFSInstance().then((ipfsApi) => {
Copy link
Member

Choose a reason for hiding this comment

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

describe('StateTransitionHeader', async () => {
  ...
  const ipfsApi = await startIPFSInstance();
  const addSTPacket = addSTPacketFactory(ipfsApi);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As far as I know, describe does not support async/await.

mochajs/mocha#2975 (comment)

Copy link
Member

Choose a reason for hiding this comment

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

:(( Promise-based syntax here looks ugly. Could we call it in before? I think we can call before in before and it should work without downsides.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That doesn't work either. Keep in mind that our solution has some trade-offs. Dealing with timeouts and hooks outside test suite make the code less explicit.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, ok. Let's keep this as is.

@@ -0,0 +1,7 @@
/* eslint-disable global-require */
describe('mocha', () => {
Copy link
Member

Choose a reason for hiding this comment

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

'Mocha'


describe('Three instances', () => {
let instances;
startDashCoreInstance.many(3).then((_instances) => {
Copy link
Member

Choose a reason for hiding this comment

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

We can use await here

Copy link
Member

@shumkov shumkov left a comment

Choose a reason for hiding this comment

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

utACK 👍

@dreyacosta dreyacosta merged commit 95a385f into master May 15, 2018
@dreyacosta dreyacosta deleted the 140-mocha-layer branch May 15, 2018 14:41
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants