git ssb

0+

wanderer🌟 / js-primea-hypervisor



Commit ee2ec06375d8aa1dbc04ba175e9de5085bfa8c42

don't start the ipfs node in tests

wanderer committed on 5/25/2017, 1:49:11 AM
Parent: 600f990b0583a4766c0311209cbe69cad38d2459

Files changed

exoInterface.jschanged
port.jschanged
portManager.jschanged
tests/index.jschanged
exoInterface.jsView
@@ -156,10 +156,10 @@
156156 * @param {Object} portRef - the port
157157 * @param {Message} message - the message
158158 */
159159 async send (portRef, message) {
160- if (!this.ports.isValid(portRef)) {
161- throw new Error('invalid port')
160+ if (!this.ports.isBound(portRef)) {
161+ throw new Error('cannot send message with an unbound port')
162162 }
163163
164164 // set the port that the message came from
165165 message._fromPort = this.entryPort
port.jsView
@@ -3,11 +3,12 @@
33 * a simple repsentation of a port
44 * @property {Interger} ticks - the last know number of ticks the
55 * corrisponding container is at
66 */
7- constructor () {
7+ constructor (name) {
88 this._queue = []
99 this.ticks = 0
10+ this.name = name
1011 }
1112
1213 /**
1314 * queues a message on the port
portManager.jsView
@@ -62,9 +62,9 @@
6262 })
6363 }
6464
6565 _bindRef (portRef, name) {
66- const port = new Port()
66+ const port = new Port(name)
6767 this._portMap.set(portRef, port)
6868 }
6969
7070 /**
@@ -97,21 +97,22 @@
9797
9898 /**
9999 * deletes a port given its name
100100 * @param {String} name
101+ * @returns {boolean} whether or not the port was deleted
101102 */
102103 delete (name) {
103104 const port = this.ports[name]
104105 delete this.ports[name]
105- this._portMap.delete(port)
106+ return this._portMap.delete(port)
106107 }
107108
108109 /**
109110 * check if a port object is still valid
110111 * @param {Object} port
111112 * @return {Boolean}
112113 */
113- isValid (port) {
114+ isBound (port) {
114115 return this._portMap.has(port)
115116 }
116117
117118 _createPortObject (type, link) {
@@ -139,14 +140,15 @@
139140
140141 /**
141142 * creates a new Port given the container type
142143 * @param {String} type
144+ * @param {*} data - the data to populate the initail state with
143145 * @returns {Object} the newly created port
144146 */
145- create (type) {
147+ create (type, data) {
146148 const Container = this.hypervisor._containerTypes[type]
147149 return this._createPortObject(type, {
148- '/': Container.createState()
150+ '/': Container.createState(data)
149151 })
150152 }
151153
152154 /**
@@ -183,9 +185,9 @@
183185 * @param {Array} ports
184186 * @returns {Promise}
185187 */
186188 async getNextMessage (ports = [...this._portMap]) {
187- if (this._portMap.size) {
189+ if (ports.length) {
188190 // find the oldest message
189191 const ticks = ports.map(([name, port]) => {
190192 return port.size ? port.ticks : this.exoInterface.ticks
191193 }).reduce((ticksA, ticksB) => {
tests/index.jsView
@@ -1,9 +1,11 @@
11 const tape = require('tape')
22 const IPFS = require('ipfs')
33 const Hypervisor = require('../')
44
5-const node = new IPFS()
5+const node = new IPFS({
6+ start: false
7+})
68
79 class BaseContainer {
810 constructor (kernel) {
911 this.kernel = kernel
@@ -16,19 +18,9 @@
1618 }
1719 }
1820 }
1921
20-node.on('error', err => {
21- console.log(err)
22-})
23-
24-node.on('start', () => {
25- tape.onFinish(() => {
26- node.stop(() => {
27- process.exit()
28- })
29- })
30-
22+node.on('ready', () => {
3123 tape('basic', async t => {
3224 t.plan(2)
3325 let message
3426 const expectedState = {

Built with git-ssb-web