Skip to content

Commit 857ba29

Browse files
authored
Merge pull request #1081 from closeio/andrzej/p1/do-not-create-extra-thread-for-syncing
Add extra test
2 parents b9f3ee5 + 0932372 commit 857ba29

File tree

4 files changed

+55
-0
lines changed

4 files changed

+55
-0
lines changed

tests/mailsync/__init__.py

Whitespace-only changes.

tests/mailsync/backends/__init__.py

Whitespace-only changes.

tests/mailsync/backends/imap/__init__.py

Whitespace-only changes.
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import threading
2+
import time
3+
from unittest import mock
4+
5+
import pytest
6+
7+
from inbox.mailsync.backends.imap.monitor import (
8+
FolderSyncEngine,
9+
ImapSyncMonitor,
10+
)
11+
12+
13+
def test_imap_sync_monitor_start_stop(mock_imapclient, db, default_account):
14+
from inbox.mailsync.gc import DeleteHandler
15+
16+
mock_imapclient.list_folders = mock.Mock(
17+
return_value=[
18+
((b"\\All", b"\\HasNoChildren"), b"/", "[Gmail]/All Mail")
19+
]
20+
)
21+
22+
monitor = ImapSyncMonitor(default_account)
23+
24+
assert monitor.is_alive() is False
25+
assert monitor.ready() is False
26+
assert monitor.successful() is False
27+
28+
monitor.start()
29+
30+
assert monitor.is_alive() is True
31+
assert monitor.ready() is False
32+
33+
# Give it a moment to start the subthreads
34+
for __ in range(100):
35+
if threading.active_count() >= 4:
36+
break
37+
time.sleep(0.1)
38+
else:
39+
pytest.fail("Timed out waiting for threads to start")
40+
41+
assert sorted(
42+
(thread.__class__ for thread in threading.enumerate()), key=repr
43+
) == [
44+
FolderSyncEngine,
45+
ImapSyncMonitor,
46+
DeleteHandler,
47+
threading._MainThread,
48+
]
49+
50+
monitor.stop()
51+
monitor.join(timeout=1)
52+
53+
assert monitor.is_alive() is False
54+
assert monitor.ready() is True
55+
assert threading.enumerate() == [threading.main_thread()]

0 commit comments

Comments
 (0)