def f(): msg = {'op': 'get-data', 'keys': ['x']} for i in range(3): sock.send(dumps(msg)) result = yield From(delay(loop, sock.recv)) assert loads(result) == {'x': 123} w.close() c.close()
def f(): msg = { 'op': 'register', 'address': 'hank', 'keys': ['x', 'y'], 'reply': True } sock.send(dumps(msg)) ack = yield From(delay(loop, sock.recv)) assert ack == b'OK' assert 'hank' in c.who_has['x'] assert 'hank' in c.who_has['y'] assert c.has_what['hank'] == set(['x', 'y']) msg = {'op': 'who-has', 'keys': ['x']} sock.send(dumps(msg)) result = yield From(delay(loop, sock.recv)) assert loads(result) == {'x': set(['hank'])} msg = {'op': 'list', 'number': 0} sock.send(dumps(msg)) result = yield From(delay(loop, sock.recv)) assert loads(result) == set(['hank']) msg = { 'op': 'unregister', 'address': 'hank', 'keys': ['x'], 'reply': True } sock.send(dumps(msg)) result = yield From(delay(loop, sock.recv)) assert c.who_has['x'] == set() assert c.who_has['y'] == set(['hank']) assert c.has_what['hank'] == set(['y']) c.close()
def f(): msg = { 'op': 'compute', 'key': 'y', 'function': add, 'args': ('x', 10), 'needed': ['x'], 'reply': True } sock.send(dumps(msg)) # send to a, will need to get from b result = yield From(delay(loop, sock.recv)) assert loads(result) == {'op': 'computation-finished', 'key': 'y'} a.close() b.close() c.close()
def f(): msg = { 'op': 'compute', 'key': 'y', 'function': add, 'args': ('asdf', 10), 'needed': ['asdf'], 'reply': True } sock.send(dumps(msg)) result = yield From(delay(loop, sock.recv)) result = loads(result) assert result['op'] == 'computation-failed' assert isinstance(result['error'], KeyError) assert 'asdf' in str(result['error']) w.close() c.close()
def f(): msg = { 'op': 'compute', 'key': 'y', 'function': add, 'args': ('x', 10), 'needed': ['x'], 'reply': True } for i in range(3): sock.send(dumps(msg)) result = yield From(delay(loop, sock.recv)) assert loads(result) == { 'op': 'computation-finished', 'key': 'y' } w.close() c.close()