Skip to content

Commit bcd351b

Browse files
author
James Dalessio
committed
Clone payloads.
1 parent ed5a452 commit bcd351b

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

exp_sdk/network.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ def __init__(self, sdk, message):
1919
self.time = int(time.time())
2020

2121
@property
22-
def payload(self):
23-
return self._message['payload']
22+
def payload (self):
23+
return json.loads(json.dumps(self._message['payload']))
2424

2525
def respond(self, response):
2626
self._sdk.api.post('/api/networks/current/responses', {'id': self._message['id'], 'channel': self._message['channel'], 'payload': response })

tests/test_network.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ def test_queue (self):
2222
time.sleep(2)
2323
channel.broadcast('m', 3)
2424
channel.broadcast('m', 4)
25+
time.sleep(.5)
2526
if not listener.wait(2).payload in [3, 4]:
2627
raise Exception
2728
if not listener.wait(2).payload in [3, 4]:
@@ -78,3 +79,17 @@ def test_listener_timeout (self):
7879
except self.exp_sdk.NetworkError:
7980
return
8081
raise Exception
82+
83+
def test_cloning (self):
84+
self.consumer_credentials['enable_network'] = True
85+
exp = self.exp_sdk.start(**self.consumer_credentials)
86+
channel = exp.get_channel('hi', consumer=True);
87+
listener1 = channel.listen('hi')
88+
listener2 = channel.listen('hi');
89+
channel.broadcast('hi', {});
90+
91+
broadcast = listener1.wait(5)
92+
broadcast.payload['a'] = 1
93+
broadcast2 = listener2.wait(5)
94+
if 'a' in broadcast.payload and broadcast.payload['a'] == 1:
95+
raise Exception

0 commit comments

Comments
 (0)