33import shutil
44import tempfile
55import unittest
6+ from unittest import mock
67import warnings
78
89from prometheus_client import mmap_dict , values
@@ -200,8 +201,11 @@ def test_gauge_mostrecent(self):
200201 g1 = Gauge ('g' , 'help' , registry = None , multiprocess_mode = 'mostrecent' )
201202 values .ValueClass = MultiProcessValue (lambda : 456 )
202203 g2 = Gauge ('g' , 'help' , registry = None , multiprocess_mode = 'mostrecent' )
203- g2 .set (2 )
204- g1 .set (1 )
204+ # Give each set() a distinct timestamp so the result doesn't depend on
205+ # clock resolution or the order the .db files are read in.
206+ with mock .patch ('prometheus_client.metrics.time.time' , side_effect = [1.0 , 2.0 ]):
207+ g2 .set (2 )
208+ g1 .set (1 )
205209 self .assertEqual (1 , self .registry .get_sample_value ('g' ))
206210 values .close_all_multiprocess_files ()
207211 mark_process_dead (123 , os .environ ['PROMETHEUS_MULTIPROC_DIR' ])
@@ -211,8 +215,11 @@ def test_gauge_livemostrecent(self):
211215 g1 = Gauge ('g' , 'help' , registry = None , multiprocess_mode = 'livemostrecent' )
212216 values .ValueClass = MultiProcessValue (lambda : 456 )
213217 g2 = Gauge ('g' , 'help' , registry = None , multiprocess_mode = 'livemostrecent' )
214- g2 .set (2 )
215- g1 .set (1 )
218+ # Give each set() a distinct timestamp so the result doesn't depend on
219+ # clock resolution or the order the .db files are read in.
220+ with mock .patch ('prometheus_client.metrics.time.time' , side_effect = [1.0 , 2.0 ]):
221+ g2 .set (2 )
222+ g1 .set (1 )
216223 self .assertEqual (1 , self .registry .get_sample_value ('g' ))
217224 values .close_all_multiprocess_files ()
218225 mark_process_dead (123 , os .environ ['PROMETHEUS_MULTIPROC_DIR' ])
0 commit comments