@@ -31,6 +31,15 @@ def __init__(self, backoff: float) -> None:
31
31
"""`backoff`: backoff time in seconds"""
32
32
self ._backoff = backoff
33
33
34
+ def __hash__ (self ) -> int :
35
+ return hash ((self ._backoff ,))
36
+
37
+ def __eq__ (self , other ) -> bool :
38
+ if not isinstance (other , ConstantBackoff ):
39
+ return NotImplemented
40
+
41
+ return self ._backoff == other ._backoff
42
+
34
43
def compute (self , failures : int ) -> float :
35
44
return self ._backoff
36
45
@@ -53,6 +62,15 @@ def __init__(self, cap: float = DEFAULT_CAP, base: float = DEFAULT_BASE):
53
62
self ._cap = cap
54
63
self ._base = base
55
64
65
+ def __hash__ (self ) -> int :
66
+ return hash ((self ._base , self ._cap ))
67
+
68
+ def __eq__ (self , other ) -> bool :
69
+ if not isinstance (other , ExponentialBackoff ):
70
+ return NotImplemented
71
+
72
+ return self ._base == other ._base and self ._cap == other ._cap
73
+
56
74
def compute (self , failures : int ) -> float :
57
75
return min (self ._cap , self ._base * 2 ** failures )
58
76
@@ -68,6 +86,15 @@ def __init__(self, cap: float = DEFAULT_CAP, base: float = DEFAULT_BASE) -> None
68
86
self ._cap = cap
69
87
self ._base = base
70
88
89
+ def __hash__ (self ) -> int :
90
+ return hash ((self ._base , self ._cap ))
91
+
92
+ def __eq__ (self , other ) -> bool :
93
+ if not isinstance (other , FullJitterBackoff ):
94
+ return NotImplemented
95
+
96
+ return self ._base == other ._base and self ._cap == other ._cap
97
+
71
98
def compute (self , failures : int ) -> float :
72
99
return random .uniform (0 , min (self ._cap , self ._base * 2 ** failures ))
73
100
@@ -83,6 +110,15 @@ def __init__(self, cap: float = DEFAULT_CAP, base: float = DEFAULT_BASE) -> None
83
110
self ._cap = cap
84
111
self ._base = base
85
112
113
+ def __hash__ (self ) -> int :
114
+ return hash ((self ._base , self ._cap ))
115
+
116
+ def __eq__ (self , other ) -> bool :
117
+ if not isinstance (other , EqualJitterBackoff ):
118
+ return NotImplemented
119
+
120
+ return self ._base == other ._base and self ._cap == other ._cap
121
+
86
122
def compute (self , failures : int ) -> float :
87
123
temp = min (self ._cap , self ._base * 2 ** failures ) / 2
88
124
return temp + random .uniform (0 , temp )
@@ -100,6 +136,15 @@ def __init__(self, cap: float = DEFAULT_CAP, base: float = DEFAULT_BASE) -> None
100
136
self ._base = base
101
137
self ._previous_backoff = 0
102
138
139
+ def __hash__ (self ) -> int :
140
+ return hash ((self ._base , self ._cap ))
141
+
142
+ def __eq__ (self , other ) -> bool :
143
+ if not isinstance (other , DecorrelatedJitterBackoff ):
144
+ return NotImplemented
145
+
146
+ return self ._base == other ._base and self ._cap == other ._cap
147
+
103
148
def reset (self ) -> None :
104
149
self ._previous_backoff = 0
105
150
@@ -121,6 +166,15 @@ def __init__(self, cap: float = DEFAULT_CAP, base: float = DEFAULT_BASE) -> None
121
166
self ._cap = cap
122
167
self ._base = base
123
168
169
+ def __hash__ (self ) -> int :
170
+ return hash ((self ._base , self ._cap ))
171
+
172
+ def __eq__ (self , other ) -> bool :
173
+ if not isinstance (other , EqualJitterBackoff ):
174
+ return NotImplemented
175
+
176
+ return self ._base == other ._base and self ._cap == other ._cap
177
+
124
178
def compute (self , failures : int ) -> float :
125
179
return min (self ._cap , random .random () * self ._base * 2 ** failures )
126
180
0 commit comments