-
Notifications
You must be signed in to change notification settings - Fork 62
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
The big refactor! #200
The big refactor! #200
Conversation
@diasdavid I'm not sure what you mean by:
All tests run in the browser, what other browser tests are missing? |
I take that back, there is indeed a suite that gets run in the browser https://github.com/ipfs/js-ipfsd-ctl/blob/master/test/browser.js#L4 |
@diasdavid right, the rest of the tests are concerned with daemon specific tests (i.e. repo exist in the filesystem, daemon cleans up correctly when killed, executable is able to resolve correctly, etc... which can't be tested from the browser). Thanks for the refactor 👍 I think it cleans up a lot of things. |
.aegir.js
Outdated
@@ -2,7 +2,8 @@ | |||
|
|||
const createServer = require('./src').createServer | |||
|
|||
const server = createServer() | |||
const server = createServer({ port: 25000 }) |
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.
Can we use port 0 to avoid port collisions?
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 spawned in a separate process by aegir, we would have to create yet another side channel just to pass this port over. Not worth it. For other cases, yes for port 0.
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.
Made good progress this morning, starting to see the light at the end of the tunnel :)
The commit history is a mess because I had to change so many things that at some point it became meaningless.
Still some work TODO though. The project is finally in a state where the structure feels right and it is simple to isolate tests and bugs. I won't be able to touch this again until tomorrow morning. If you have time to contribute, please do :)
| +-----------------------+ | +-----------------------|---- | | | ||
| | | +----------------------+ | | ||
+-----------------------------+ +-----------------------------+ | ||
``` |
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.
Needs a new diagram.
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.
What is the current diagram missing?
└── tmp-dir.js | ||
|
||
4 directories, 21 files | ||
``` |
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 finally happy with the code structure :)
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.
Here for reference:
src
├── defaults
│ ├── config.json
│ └── options.json
├── endpoint # endpoint to support remote spawning
│ ├── routes.js
│ └── server.js
├── factory-client.js # IPFS Factories: client (remote), daemon (go or js) and in-proc (js)
├── factory-daemon.js
├── factory-in-proc.js
├── index.js
├── ipfsd-client.js # ipfsd (Daemon Controller): client (remote), daemon (go or js), in-proc (js)
├── ipfsd-daemon.js
├── ipfsd-in-proc.js
└── utils # Utils used by the Factories and Daemon Controllers
├── configure-node.js
├── exec.js
├── find-ipfs-executable.js
├── flatten.js
├── parse-config.js
├── repo
│ ├── create-browser.js
│ └── create-nodejs.js
├── run.js
├── set-config-value.js
└── tmp-dir.js
4 directories, 21 files
const ctrl = new CtrlFactory({ type: payload.type }) | ||
ctrl.spawn(payload.opts, (err, ipfsd) => { | ||
|
||
// TODO: use the ../src/index.js so that the right Factory is picked |
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.
- 🌟
src/factory-daemon.js
Outdated
} | ||
options = Object.assign({}, options, { type: this.type }) | ||
// TODO: (1) this should check to see if it is looking for Go or JS | ||
// TODO: (2) This spawns a whole daemon just to get his version? There is |
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.
- 🌟
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.
just doing new Daemon
won't actually start the daemon, it will simply allow you to send commands to the selected executable.
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 still should check if it is JS or Go
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.
Why? All the logic around daemon type is already being handled in the Daemon
itself - not sure what to do with the check here.
src/factory-in-proc.js
Outdated
callback = options | ||
options = {} | ||
} | ||
// TODO create this method |
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.
- 🌟
src/ipfsd-daemon.js
Outdated
@@ -323,7 +327,8 @@ class Node { | |||
), | |||
(config, cb) => { | |||
if (!key) { | |||
return tryJsonParse(config, cb) | |||
// TODO: this function didn't exist on the original codebase | |||
// return tryJsonParse(config, cb) |
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.
- Figure out why this was here in the first place.
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.
because the daemon process will return a json string back, not an object.
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.
@dryajov even if that is correct, the tryJsonParse
function doesn't seem to exist anywhere in the codebase
test/start-stop.node.js
Outdated
expect(ipfsd).to.exist() | ||
}) | ||
|
||
// TODO fix this test |
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.
- 🌟
test/start-stop.node.js
Outdated
it('.start with flags', (done) => { | ||
// TODO js-ipfs doesn't fail on unrecognized args. Think what should be | ||
// the desired behaviour | ||
if (type === 'js') { return this.skip() } |
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.
- 🌟
src/factory-in-proc.js
Outdated
@@ -3,44 +3,20 @@ | |||
const defaults = require('lodash.defaultsdeep') |
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.
why duplicate if factory-in-proc share %90+ code with factory-daemon?
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.
We should have a base class then. The main reason is that you want to avoid having factory-daemon being loaded in the browser (and all of its dependencies).
@@ -0,0 +1,63 @@ | |||
/* eslint-env mocha */ |
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 was originally intended as a set of reusable tests to run after the different combinations of spawn/init/start
to make sure the daemon were being created in a functional way - this intent is lost with this change. How are we testing for this cases?
test/spawn-options.node.js
Outdated
df = DaemonFactory.create(dfOpts) | ||
}) | ||
|
||
// TODO: why does ipfsd-ctl polute the env variables? |
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 used to set IPFS_PATH and other variables, its not the case anymore - we can remove that.
test/spawn-options.node.js
Outdated
const options = { | ||
init: false, | ||
start: false, | ||
disposable: true |
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 needs to be false
test/spawn-options.node.js
Outdated
}) | ||
|
||
// TODO ?? What is this test trying to prove? | ||
describe('spawn a node and attach api', () => { |
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.
confusing name for the test - its trying to make sure that starting the node withspawn
with the default options will return a fully constructed ipfsd
object. The reusable tests I pointed to above where there to make sure it was also started and initialized correct and permitted to interact with it over the attached ipfs-api
.
test/spawn-options.node.js
Outdated
} | ||
], (err) => { | ||
expect(err).to.not.exist() | ||
expect(fs.existsSync(repoPath)).to.be.ok() |
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.
// TODO why wouldn't this work from the browser if we use the
// remote endpoint?
because we use fs.existsSync
- is there a way of making it work in the browser?
@diasdavid I took on fixing some of the outstanding todos as well as making sure all tests pass in node. |
README.md
Outdated
|
||
## Table of Contents | ||
|
||
- [Install](#install) | ||
- [Usage](#usage) | ||
- [API](#api) | ||
- [Packageing](#packaging) |
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.
- typo
src/factory-client.js
Outdated
callback = options | ||
options = {} | ||
} | ||
// TODO implement this method |
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 method needs to be implemented as well for clients. Once it is, enable tests again.
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.
In progress, will push shortly.
src/factory-daemon.js
Outdated
} | ||
options = Object.assign({}, options, { type: this.type }) | ||
// TODO: (1) this should check to see if it is looking for Go or JS | ||
// TODO: (2) This spawns a whole daemon just to get his version? There is |
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 still should check if it is JS or Go
eb51dab
to
581945e
Compare
src/factory-in-proc.js
Outdated
const nonDisposableConfig = clone(defaultConfig) | ||
delete nonDisposableConfig.Addresses | ||
// TODO why delete the addrs here??? | ||
// delete nonDisposableConfig.Addresses |
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.
@dryajov why were you deleting the addrs here?
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.
Because at some point we wanted non-disposable nodes to use js-ipfs
or go-ipfs
default ports and not random ports.
src/factory-daemon.js
Outdated
@@ -26,7 +26,7 @@ class FactoryDaemon { | |||
if (options && options.type === 'proc') { | |||
throw new Error('This Factory does not know how to spawn in proc nodes') | |||
} | |||
options = Object.assign({ type: 'go' }, options) | |||
options = Object.assign({}, { type: 'go' }, options) |
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.
@dryajov why this change?
src/factory-in-proc.js
Outdated
@@ -4,11 +4,14 @@ const defaults = require('lodash.defaultsdeep') | |||
const clone = require('lodash.clone') | |||
const waterfall = require('async/waterfall') | |||
const path = require('path') | |||
const tmpDir = require('./utils/tmp-dir') |
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 brought the os module to the browser.
The current ipfsd-ctl is a big mess. There are
noonly a few browser tests; tests have the setup assert and teardown phases all mixed with sometimes using a describe + before as the assertion; there are multiple files that get loaded in the browser without necessity, this is causing all sorts of problems on other modules ipfs-inactive/js-ipfs-http-client#683; The internals use different names for the things that are exposed (i.e calling daemon-ctrl to the Daemon Factory).There is still a considerable amount of work to do here. I might not be able to finish this today but I intend to have it tomorrow.