orbitdb-archive / orbit-db-test-utils

Shared test utilities for OrbitDB-related projects
MIT License
6 stars 11 forks source link

refactor: update deps, add tests, make more lightweight #11

Closed aphelionz closed 4 years ago

aphelionz commented 4 years ago

This PR updates:

Also, updating ipfsd-ctl allowed me to (at least attempt to) clean up this a bit. I ~removed startIpfs and stopIpfs~ created a factory object with preferred configuration from ipfsd-ctl. I extended the prototype to create two new functions to the factory:

  1. spawnApi to deal with the simple boilerplate of:
const ipfsd = factory.spawn()
const ipfs = ipfsd.api
  1. localCluster, which is where the real magic [can] happen, which takes an array of ipfs types like js, go, proc, etc, connects them all via permutation, and then returns the array of connected nodes.

It will take refactoring the downstream tests a but but I believe this gives us a few advantages:

  1. We can spawn as many daemons, in whatever configuration we want, as we want during our tests, including js and go nodes in the same tests, while also still being able to loop through ['js', 'go'] in our tests like we usually do, if we want. Note that we can also still use waitForPeers, and connectPeers.
  2. We can use the factory.clean() method in the after methods in our mocha tests to properly clean up all the spawned daemons and not run into any more issues where the process doesn't close.
  3. ~Less code overall,~

Tradeoffs

TODO if/when approved

npm install time on master (Thinkpad W540, 8 cores, 24GB ram)

real 1m32.161s user 1m26.220s sys 0m11.440s

Code coverage:

------------------------|---------|----------|---------|---------|-------------------
File                    | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
------------------------|---------|----------|---------|---------|-------------------
All files               |   94.44 |    74.19 |      88 |   96.55 |
 orbit-db-test-utils    |    97.2 |    82.61 |     100 |   98.02 |
  connect-peers.js      |     100 |      100 |     100 |     100 |
  get-ipfs-peer-id.js   |     100 |      100 |     100 |     100 |
  index.js              |     100 |      100 |     100 |     100 |
  mem-store.js          |      96 |       75 |     100 |      96 | 9
  start-ipfs.js         |      90 |      100 |     100 |      90 | 21
  stop-ipfs.js          |     100 |      100 |     100 |     100 |
  swarm.js              |   96.15 |     87.5 |     100 |     100 | 33
  wait-for-peers.js     |     100 |       50 |     100 |     100 | 11
 ...b-test-utils/config |    87.5 |       50 |     100 |     100 |
  factory.js            |     100 |      100 |     100 |     100 |
  index.js              |   83.33 |       50 |     100 |     100 | 4-5
  node.js               |     100 |      100 |     100 |     100 |
 ...ils/implementations |   72.73 |       50 |       0 |   77.78 |
  index.js              |   83.33 |       50 |     100 |     100 | 4-5
  node.js               |      60 |      100 |       0 |      60 | 51-55
------------------------|---------|----------|---------|---------|-------------------
oed commented 4 years ago

You are a hero 🙌

aphelionz commented 4 years ago

Opted not to re-export Ctl but instead create a factory with the settings we'd want, and then extended that factory's prototype to include two functions:

  1. spawnApi to deal with the simple boilerplate of:
const ipfsd = factory.spawn()
const ipfs = ipfsd.api
  1. localCluster, which is where the real magic [can] happen, which takes an array of ipfs types like js, go, proc, etc, connects them all via permutation, and then returns the array of connected nodes.

I'm only testing with proc right now. I think this approach will be promising and I'll be playing with using it in ipfs-log tomorrow.

~I also may put back startIpfs and stopIpfs just so I'm not needlessly breaking the previously written tests.~

aphelionz commented 4 years ago

startIpfs, stopIpfs, and testApis were restored to not unnecessarily break existing tests, and a deprecation warning was added.

aphelionz commented 4 years ago

Ran into an error after rm -rf node_modules package-lock.json and npm install:

     Error: invalid block
      at Object.put (node_modules/ipfs-repo/src/blockstore.js:76:15)
      at BlockService.put (node_modules/ipfs-block-service/src/index.js:63:32)
      at IPLDResolver.put (node_modules/ipld/src/index.js:196:21)
      at async Object.put (node_modules/ipfs/src/core/components/dag/put.js:48:1
9)
      at async Proxy.init (node_modules/ipfs/src/core/components/init.js:128:27)
      at async InProc.init (node_modules/ipfsd-ctl/src/ipfsd-in-proc.js:93:5)
      at async Factory.spawn (node_modules/ipfsd-ctl/src/factory.js:141:7)
      at async Promise.all (index 5)
      at async Factory.factory.constructor.localSwarm (index.js:5:692)
      at async Context.<anonymous> (test/workflow.spec.js:91:21)