Skip to content

Commit

Permalink
introducing results_read signal - that is what's fired by read_all
Browse files Browse the repository at this point in the history
  • Loading branch information
zsoldosp committed Jun 21, 2017
1 parent a8c0d31 commit 62abd71
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 3 deletions.
7 changes: 5 additions & 2 deletions django_performance_testing/serializer.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from django.utils.six.moves import cPickle as pickle
from django_performance_testing.signals import results_collected
from django_performance_testing.signals import results_collected, results_read


class Reader:
Expand All @@ -11,7 +11,10 @@ def read_all(self):
data = f.read()
if not data:
return []
return pickle.loads(data)
deserialized = pickle.loads(data)
for (sender, results, context) in deserialized:
results_read.send(sender=sender, results=results, context=context)
return deserialized


class Writer:
Expand Down
2 changes: 2 additions & 0 deletions django_performance_testing/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@
results_collected = Signal(providing_args=('results', 'context'))

before_clearing_queries_log = Signal(providing_args=['queries'])

results_read = Signal(providing_args=('results', 'context'))
27 changes: 26 additions & 1 deletion tests/testapp/tests/test_serialization.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pytest
from django_performance_testing import serializer
from django_performance_testing.signals import results_collected
from django_performance_testing.signals import results_collected, results_read
from testapp.test_helpers import FakeSender, WithId


Expand Down Expand Up @@ -70,6 +70,31 @@ def test_writer_only_writes_when_end_is_called(tmpfilepath):
assert deserialized == [(WithId('after start'), [2], {'after': 'start'})]


def test_read_all_fires_results_read_signals(tmpfilepath):
writer = serializer.Writer(tmpfilepath)
writer.start()
results_collected.send(
sender=WithId('after start'), results=[2],
context={'after': 'start'})
writer.end()
results_from_results_read_signal = []

def record_read_results(sender, results, context, **kwargs):
results_from_results_read_signal.append((
sender, results, context
))

results_read.connect(record_read_results)
reader = serializer.Reader(tmpfilepath)
deserialized = reader.read_all()
try:
assert deserialized != []
assert results_from_results_read_signal != []
assert results_from_results_read_signal == deserialized
finally:
results_read.disconnect(record_read_results)


@pytest.mark.parametrize('sender_id,sender_type', [
('sender_id_1', 'sender_type_1'),
('sender_id_2', 'sender_type_2'),
Expand Down

0 comments on commit 62abd71

Please sign in to comment.