Browse Source

random timing for minimail

PYADPT-55
Volker Birk 2 years ago
parent
commit
dcbbbca020
4 changed files with 27 additions and 12 deletions
  1. +14
    -6
      test/minimail.py
  2. +7
    -4
      test/sync_handshake.py
  3. +5
    -1
      test/sync_test.py
  4. +1
    -1
      utils/pEp

+ 14
- 6
test/minimail.py View File

@ -13,8 +13,8 @@ delete the marker file to re-read all messages
"""
# Minimail 1.1
# Copyleft 2019, p≡p foundation
# Minimail 1.2
# Copyleft 2019, 2020, p≡p foundation
# this file is under GNU General Public License 3.0
@ -22,11 +22,19 @@ delete the marker file to re-read all messages
import os
from secrets import token_urlsafe
from time import sleep
from random import random
timing = .1
# set timing to None for random timing
timing = None
def snooze():
if timing is None:
sleep(random()/2)
else:
sleep(timing)
def unlock(inbox):
"clear the inbox from lockfile"
@ -49,14 +57,14 @@ class Lock:
def __enter__(self):
lockfile = self.inbox / "lock"
while lockfile.is_file():
sleep(timing)
snooze()
lockfile.touch()
def send(inbox, msg, marker):
"send msg to inbox in MIME format"
sleep(timing)
snooze()
with Lock(inbox):
name = marker + "_" + token_urlsafe(16) + ".eml"
with open(inbox / name, "wb") as f:
@ -95,7 +103,7 @@ def recv_all(inbox, marker):
txt = f.read(-1)
r.append((p, txt))
if not r:
sleep(timing)
snooze()
return r

+ 7
- 4
test/sync_handshake.py View File

@ -130,10 +130,11 @@ class UserInterface(pEp.UserInterface):
])
sleep(.5) # user is reading message
try:
if options.reject:
self.deliverHandshakeResult(SYNC_HANDSHAKE_REJECTED)
else:
self.deliverHandshakeResult(SYNC_HANDSHAKE_ACCEPTED)
if not options.noanswer:
if options.reject:
self.deliverHandshakeResult(SYNC_HANDSHAKE_REJECTED)
else:
self.deliverHandshakeResult(SYNC_HANDSHAKE_ACCEPTED)
except NameError:
self.deliverHandshakeResult(SYNC_HANDSHAKE_ACCEPTED)
@ -234,6 +235,8 @@ if __name__=="__main__":
help="reject device group")
optParser.add_option("--accept", action="store_false", dest="reject",
help="accept device group (default)")
optParser.add_option("--no-answer", action="store_true", dest="noanswer",
help="do not answer device group handshake")
optParser.add_option("-E", "--end-on", dest="notifications",
help="end test on these notifications")
optParser.add_option("-j", "--multi-threaded", action="store_true",


+ 5
- 1
test/sync_test.py View File

@ -102,6 +102,10 @@ if __name__ == "__main__":
optParser.add_option("-i", "--imap", action="store_true",
dest="imap",
help="use imap instead of minimail")
optParser.add_option("-A", "--add-account-after-sync", action="store_true",
dest="add_account",
help="after sync add an account")
options, args = optParser.parse_args()
if options.imap:
@ -207,7 +211,7 @@ if __name__ == "__main__":
# Phone runs with own_ident = 2
Phone = Process(target=test_for, args=("Phone", "red", end_on,
options.multithreaded, options.imap, 2))
options.multithreaded, options.imap, 1))
# others run with own_ident = 1
Laptop = Process(target=test_for, args=("Laptop", "green", end_on,


+ 1
- 1
utils/pEp View File

@ -72,7 +72,7 @@ try:
dst = src.encrypt()
else:
src.dir = 0
dst, keys, rating, consumed, flags = src.decrypt()
dst, keys, rating, flags = src.decrypt()
print(str(dst))


Loading…
Cancel
Save