Commit db8690a1d23bec923250cdf8757fc222ee7236b3
added checks for bound names
wanderer committed on 6/3/2017, 7:05:48 PMParent: 6496226a003a3eb1845cd6d43c4cdde5fca7b665
Files changed
portManager.js | changed |
tests/index.js | changed |
portManager.js | ||
---|---|---|
@@ -51,22 +51,22 @@ | ||
51 | 51 … | */ |
52 | 52 … | async start () { |
53 | 53 … | // skip the root, since it doesn't have a parent |
54 | 54 … | if (this.parentPort !== undefined) { |
55 | - this._bindRef(this.parentPort, ENTRY) | |
55 … | + this._bindHandle(this.parentPort, ENTRY) | |
56 | 56 … | } |
57 | 57 … | |
58 | 58 … | // map ports to thier id's |
59 | 59 … | this.ports = await this.hypervisor.graph.get(this.state, 'ports') |
60 | 60 … | Object.keys(this.ports).map(name => { |
61 | 61 … | const port = this.ports[name] |
62 | - this._bindRef(port, name) | |
62 … | + this._bindHandle(port, name) | |
63 | 63 … | }) |
64 | 64 … | } |
65 | 65 … | |
66 | - _bindRef (portRef, name) { | |
66 … | + _bindHandle (portHandle, name) { | |
67 | 67 … | const port = new Port(name) |
68 | - this._portMap.set(portRef, port) | |
68 … | + this._portMap.set(portHandle, port) | |
69 | 69 … | } |
70 | 70 … | |
71 | 71 … | /** |
72 | 72 … | * binds a port to a name |
@@ -75,12 +75,14 @@ | ||
75 | 75 … | */ |
76 | 76 … | bind (port, name) { |
77 | 77 … | if (this.isBound(port)) { |
78 | 78 … | throw new Error('cannot bind a port that is already bound') |
79 … | + } else if (this.ports[name]) { | |
80 … | + throw new Error('cannot bind port to a name that is alread bound') | |
79 | 81 … | } |
80 | 82 … | // save the port instance |
81 | 83 … | this.ports[name] = port |
82 | - this._bindRef(port, name) | |
84 … | + this._bindHandle(port, name) | |
83 | 85 … | } |
84 | 86 … | |
85 | 87 … | /** |
86 | 88 … | * unbinds a port given its name |
@@ -165,16 +167,8 @@ | ||
165 | 167 … | }) |
166 | 168 … | } |
167 | 169 … | |
168 | 170 … | /** |
169 | - * creates a copy of a port given a port referance | |
170 | - * @param {Object} port - the port to copy | |
171 | - */ | |
172 | - copy (port, type = port.type) { | |
173 | - return this._createPortObject(port.type, port.link) | |
174 | - } | |
175 | - | |
176 | - /** | |
177 | 171 … | * waits till all ports have reached a threshold tick count |
178 | 172 … | * @param {Integer} threshold - the number of ticks to wait |
179 | 173 … | * @param {Object} fromPort - the port requesting the wait |
180 | 174 … | * @param {Array} ports - the ports to wait on |
tests/index.js | ||
---|---|---|
@@ -668,22 +668,10 @@ | ||
668 | 668 … | const foundThird = await hypervisor.getInstanceByPath(root, 'first/second/third') |
669 | 669 … | t.equals(third, foundThird, 'should find by path') |
670 | 670 … | }) |
671 | 671 … | |
672 | - tape('copy ports', async t => { | |
673 | - t.plan(1) | |
674 | - const hypervisor = new Hypervisor(node.dag) | |
675 | - hypervisor.registerContainer('base', BaseContainer) | |
676 | - | |
677 | - const root = await hypervisor.createInstance('base') | |
678 | - let port = root.ports.create('base') | |
679 | - let port2 = root.ports.copy(port) | |
680 | - | |
681 | - t.equals(port2.type, port.type, 'should copy port type') | |
682 | - }) | |
683 | - | |
684 | 672 … | tape('checking ports', async t => { |
685 | - t.plan(4) | |
673 … | + t.plan(5) | |
686 | 674 … | const hypervisor = new Hypervisor(node.dag) |
687 | 675 … | hypervisor.registerContainer('base', BaseContainer) |
688 | 676 … | |
689 | 677 … | const root = await hypervisor.createInstance('base') |
@@ -705,8 +693,15 @@ | ||
705 | 693 … | } catch (e) { |
706 | 694 … | t.pass('should thow if binding an already bound port') |
707 | 695 … | } |
708 | 696 … | |
697 … | + try { | |
698 … | + let port2 = root.ports.create('base') | |
699 … | + root.ports.bind(port2, 'test') | |
700 … | + } catch (e) { | |
701 … | + t.pass('should thow if binding an already bound name') | |
702 … | + } | |
703 … | + | |
709 | 704 … | root.ports.unbind('test') |
710 | 705 … | const message = root.createMessage({ports: [port]}) |
711 | 706 … | t.equals(message.ports[0], port, 'should create a message if the port is unbound') |
712 | 707 … | }) |
Built with git-ssb-web