File tree Expand file tree Collapse file tree 3 files changed +16
-4
lines changed Expand file tree Collapse file tree 3 files changed +16
-4
lines changed Original file line number Diff line number Diff line change 1
1
from typing import Dict
2
2
3
3
MAJOR : int = 1
4
- MINOR : int = 0
4
+ MINOR : int = 1
5
5
PATCH : int = 0
6
6
SUFFIX : str = ""
7
7
Original file line number Diff line number Diff line change 1
1
import datetime
2
2
import ipaddress
3
- from multiprocessing import Lock
4
3
from socket import gethostbyname , gethostname
4
+ from threading import Lock
5
5
from time import sleep
6
6
from typing import Callable , Dict , Optional
7
7
Original file line number Diff line number Diff line change 1
- import multiprocessing
2
- from collections import Counter
1
+ import threading
3
2
from datetime import datetime , timedelta
4
3
from random import randint
5
4
from time import sleep
@@ -64,3 +63,16 @@ def test_sonyflake_for_10sec(self):
64
63
self .assertEqual (
65
64
max_sequence , (1 << BIT_LEN_SEQUENCE ) - 1 , "Unexpected max sequence"
66
65
)
66
+
67
+ def test_sonyflake_in_parallel (self ):
68
+ threads = []
69
+ results = []
70
+ for _ in range (10000 ):
71
+ thread = threading .Thread (target = lambda : results .append (self .sf .next_id ()))
72
+ thread .start ()
73
+ threads .append (thread )
74
+ for thread in threads :
75
+ thread .join ()
76
+ result_set = set (results )
77
+ self .assertEqual (len (results ), len (result_set ))
78
+ self .assertCountEqual (results , result_set )
You can’t perform that action at this time.
0 commit comments