summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJon Newson <jon_newson@ieee.org>2016-02-25 07:14:06 +1100
committerJon Newson <jon_newson@ieee.org>2016-02-25 07:14:06 +1100
commitc1f468abad6717fcabc2d812e34f4217215e70a8 (patch)
tree8ee1d7fe6463eaf5edad736d8d7b058a360b78f1
parent47df3a86d7cf412d766f8a1fdd1e9b9fe15bfb45 (diff)
parent6160633ab9a54238974af3cf498024ad98fc977e (diff)
Merge commit '6160633ab9a54238974af3cf498024ad98fc977e'
* commit '6160633ab9a54238974af3cf498024ad98fc977e': Fix repositore clone url Returning 'not-sign' for no signature information Only do initial sync on session creation Improve stopwatch output Improve error message if send mail fails
-rw-r--r--README.md2
-rw-r--r--service/pixelated/bitmask_libraries/session.py12
-rw-r--r--service/pixelated/resources/mails_resource.py2
-rw-r--r--service/pixelated/support/__init__.py30
-rw-r--r--service/test/unit/bitmask_libraries/test_session.py31
-rw-r--r--web-ui/app/js/mail_view/ui/mail_view.js4
-rw-r--r--web-ui/test/spec/mail_view/ui/mail_view.spec.js2
7 files changed, 67 insertions, 16 deletions
diff --git a/README.md b/README.md
index 11e31ab9..20fdc535 100644
--- a/README.md
+++ b/README.md
@@ -22,7 +22,7 @@ You are most welcome to contribute to the pixelated user agent code base. Please
2) Clone the repo and start the virtual machine (downloads 600MB):
```
-$ git clone https://github.com/pixelated-project/pixelated-user-agent.git
+$ git clone https://github.com/pixelated/pixelated-user-agent.git
$ cd pixelated-user-agent
$ vagrant up
```
diff --git a/service/pixelated/bitmask_libraries/session.py b/service/pixelated/bitmask_libraries/session.py
index 9e908ce5..f28d9f59 100644
--- a/service/pixelated/bitmask_libraries/session.py
+++ b/service/pixelated/bitmask_libraries/session.py
@@ -53,12 +53,20 @@ class LeapSession(object):
self.fresh_account = False
self.incoming_mail_fetcher = None
self.account = None
+ self._has_been_synced = False
+ self._sem_intial_sync = defer.DeferredLock()
register(events.KEYMANAGER_FINISHED_KEY_GENERATION, self._set_fresh_account, uid=self.account_email())
@defer.inlineCallbacks
def initial_sync(self):
- yield self.sync()
- yield self.after_first_sync()
+ yield self._sem_intial_sync.acquire()
+ try:
+ if not self._has_been_synced:
+ yield self.sync()
+ yield self.after_first_sync()
+ self._has_been_synced = True
+ finally:
+ yield self._sem_intial_sync.release()
defer.returnValue(self)
@defer.inlineCallbacks
diff --git a/service/pixelated/resources/mails_resource.py b/service/pixelated/resources/mails_resource.py
index 1c322d35..c87d4ca2 100644
--- a/service/pixelated/resources/mails_resource.py
+++ b/service/pixelated/resources/mails_resource.py
@@ -183,7 +183,7 @@ class MailsResource(BaseResource):
if isinstance(error.value, SMTPDownException):
respond_json_deferred({'message': str(error.value)}, request, status_code=503)
else:
- err(error, 'something failed')
+ err(error, 'error occurred while sending')
respond_json_deferred({'message': 'an error occurred while sending'}, request, status_code=422)
deferred = self._handle_post(request)
diff --git a/service/pixelated/support/__init__.py b/service/pixelated/support/__init__.py
index 80ecaa2e..9ac52fe0 100644
--- a/service/pixelated/support/__init__.py
+++ b/service/pixelated/support/__init__.py
@@ -22,13 +22,34 @@ from twisted.internet import defer
log = logging.getLogger(__name__)
+def _start_stopwatch():
+ return (time.time(), time.clock())
+
+
+def _stop_stopwatch(start):
+ start_time, start_clock = start
+ end_clock = time.clock()
+ end_time = time.time()
+ clock_duration = end_clock - start_clock
+ time_duration = end_time - start_time
+ if time_duration < 0.00000001: # avoid division by zero
+ time_duration = 0.00000001
+
+ estimate_percent_io = ((time_duration - clock_duration) / time_duration) * 100.0
+
+ return time_duration, clock_duration, estimate_percent_io
+
+
def log_time(f):
@wraps(f)
def wrapper(*args, **kwds):
- start = time.clock()
+ start = _start_stopwatch()
+
result = f(*args, **kwds)
- log.info('Needed %f ms to execute %s' % ((time.clock() - start), f))
+
+ time_duration, clock_duration, estimate_percent_io = _stop_stopwatch(start)
+ log.info('Needed %fs (%fs cpu time, %.2f%% spent outside process) to execute %s' % (time_duration, clock_duration, estimate_percent_io, f))
return result
@@ -38,12 +59,13 @@ def log_time(f):
def log_time_deferred(f):
def log_time(result, start):
- log.info('after callback: Needed %f ms to execute %s' % ((time.clock() - start), f))
+ time_duration, clock_duration, estimate_percent_io = _stop_stopwatch(start)
+ log.info('after callback: Needed %fs (%fs cpu time, %.2f%% spent outside process) to execute %s' % (time_duration, clock_duration, estimate_percent_io, f))
return result
@wraps(f)
def wrapper(*args, **kwds):
- start = time.clock()
+ start = _start_stopwatch()
result = f(*args, **kwds)
if isinstance(result, defer.Deferred):
result.addCallback(log_time, start=start)
diff --git a/service/test/unit/bitmask_libraries/test_session.py b/service/test/unit/bitmask_libraries/test_session.py
index 22c2b3d9..a41cb805 100644
--- a/service/test/unit/bitmask_libraries/test_session.py
+++ b/service/test/unit/bitmask_libraries/test_session.py
@@ -16,7 +16,7 @@
from mock import patch
from mock import MagicMock
-
+from twisted.internet import defer
from pixelated.bitmask_libraries.session import LeapSession, SessionCache
from test_abstract_leap import AbstractLeapTest
from leap.common.events.catalog import KEYMANAGER_FINISHED_KEY_GENERATION
@@ -28,14 +28,22 @@ class SessionTest(AbstractLeapTest):
super(SessionTest, self).setUp()
self.smtp_mock = MagicMock()
- def test_background_jobs_are_started_during_initial_sync(self):
+ @patch('pixelated.bitmask_libraries.session.register')
+ @patch('pixelated.bitmask_libraries.session.IMAPAccount')
+ @defer.inlineCallbacks
+ def test_background_jobs_are_started_during_initial_sync(self, *unused):
+ mailFetcherMock = MagicMock()
with patch('pixelated.bitmask_libraries.session.reactor.callFromThread', new=_execute_func) as _:
- with patch('pixelated.bitmask_libraries.session.LeapSession._create_incoming_mail_fetcher') as mail_fetcher_mock:
+ with patch.object(LeapSession, '_create_incoming_mail_fetcher', return_value=mailFetcherMock) as _:
session = self._create_session()
yield session.initial_sync()
- mail_fetcher_mock.startService.assert_called_once()
+ mailFetcherMock.startService.assert_called_once()
- def test_that_close_stops_background_jobs(self):
+ @patch('pixelated.bitmask_libraries.session.register')
+ @patch('pixelated.bitmask_libraries.session.unregister')
+ @patch('pixelated.bitmask_libraries.session.IMAPAccount')
+ @defer.inlineCallbacks
+ def test_that_close_stops_background_jobs(self, *unused):
with patch('pixelated.bitmask_libraries.session.reactor.callFromThread', new=_execute_func) as _:
with patch('pixelated.bitmask_libraries.session.LeapSession._create_incoming_mail_fetcher') as mail_fetcher_mock:
session = self._create_session()
@@ -133,6 +141,19 @@ class SessionTest(AbstractLeapTest):
self.assertFalse(session.fresh_account)
+ @patch('pixelated.bitmask_libraries.session.register')
+ @patch('pixelated.bitmask_libraries.session.unregister')
+ @patch('pixelated.bitmask_libraries.session.IMAPAccount')
+ @defer.inlineCallbacks
+ def test_session_initial_sync_only_triggered_once(self, *unused):
+ mailFetcherMock = MagicMock()
+ with patch('pixelated.bitmask_libraries.session.reactor.callFromThread', new=_execute_func) as _:
+ with patch.object(LeapSession, '_create_incoming_mail_fetcher', return_value=mailFetcherMock) as _:
+ session = self._create_session()
+ session._has_been_synced = True
+ yield session.initial_sync()
+ self.assertFalse(mailFetcherMock.startService.called)
+
def _create_session(self):
return LeapSession(self.provider, self.auth, self.mail_store, self.soledad_session, self.nicknym, self.smtp_mock)
diff --git a/web-ui/app/js/mail_view/ui/mail_view.js b/web-ui/app/js/mail_view/ui/mail_view.js
index ba4d6e85..d4f5dd9e 100644
--- a/web-ui/app/js/mail_view/ui/mail_view.js
+++ b/web-ui/app/js/mail_view/ui/mail_view.js
@@ -51,7 +51,7 @@ define(
data.mail.security_casing = data.mail.security_casing || {};
signed = this.checkSigned(data.mail);
encrypted = this.checkEncrypted(data.mail);
- attachments = data.mail.attachments.map(function (attachment) {
+ attachments = data.mail.attachments.map(function (attachment) {
attachment.received = true;
return attachment;
});
@@ -125,7 +125,7 @@ define(
});
if(hasNoSignatureInformation) {
- return '';
+ return 'not-signed';
}
var status = ['signed'];
diff --git a/web-ui/test/spec/mail_view/ui/mail_view.spec.js b/web-ui/test/spec/mail_view/ui/mail_view.spec.js
index 1c1446f9..ae874621 100644
--- a/web-ui/test/spec/mail_view/ui/mail_view.spec.js
+++ b/web-ui/test/spec/mail_view/ui/mail_view.spec.js
@@ -165,7 +165,7 @@ describeComponent('mail_view/ui/mail_view', function () {
it('assumes that there is no signature info to show', function() {
var email = testData;
email.security_casing = {imprints: [{state: 'no_signature_information'}]};
- expect(this.component.checkSigned(email)).toEqual('');
+ expect(this.component.checkSigned(email)).toEqual('not-signed');
});
it('shows that mail is encrypted if it is', function() {