@@ -259,22 +259,6 @@ def test_write_points_udp(self):
259
259
received_data .decode ()
260
260
)
261
261
262
- def test_write_bad_precision_udp (self ):
263
- """Test write bad precision in UDP for TestInfluxDBClient object."""
264
- cli = InfluxDBClient (
265
- 'localhost' , 8086 , 'root' , 'root' ,
266
- 'test' , use_udp = True , udp_port = 4444
267
- )
268
-
269
- with self .assertRaisesRegexp (
270
- Exception ,
271
- "InfluxDB only supports seconds precision for udp writes"
272
- ):
273
- cli .write_points (
274
- self .dummy_points ,
275
- time_precision = 'ms'
276
- )
277
-
278
262
@raises (Exception )
279
263
def test_write_points_fails (self ):
280
264
"""Test write points fail for TestInfluxDBClient object."""
@@ -335,6 +319,65 @@ def test_write_points_with_precision(self):
335
319
m .last_request .body ,
336
320
)
337
321
322
+ def test_write_points_with_precision_udp (self ):
323
+ """Test write points with precision for TestInfluxDBClient object."""
324
+ s = socket .socket (socket .AF_INET , socket .SOCK_DGRAM )
325
+ port = random .randint (4000 , 8000 )
326
+ s .bind (('0.0.0.0' , port ))
327
+
328
+ cli = InfluxDBClient (
329
+ 'localhost' , 8086 , 'root' , 'root' ,
330
+ 'test' , use_udp = True , udp_port = port
331
+ )
332
+
333
+ cli .write_points (self .dummy_points , time_precision = 'n' )
334
+ received_data , addr = s .recvfrom (1024 )
335
+ self .assertEqual (
336
+ b'cpu_load_short,host=server01,region=us-west '
337
+ b'value=0.64 1257894000123456000\n ' ,
338
+ received_data ,
339
+ )
340
+
341
+ cli .write_points (self .dummy_points , time_precision = 'u' )
342
+ received_data , addr = s .recvfrom (1024 )
343
+ self .assertEqual (
344
+ b'cpu_load_short,host=server01,region=us-west '
345
+ b'value=0.64 1257894000123456\n ' ,
346
+ received_data ,
347
+ )
348
+
349
+ cli .write_points (self .dummy_points , time_precision = 'ms' )
350
+ received_data , addr = s .recvfrom (1024 )
351
+ self .assertEqual (
352
+ b'cpu_load_short,host=server01,region=us-west '
353
+ b'value=0.64 1257894000123\n ' ,
354
+ received_data ,
355
+ )
356
+
357
+ cli .write_points (self .dummy_points , time_precision = 's' )
358
+ received_data , addr = s .recvfrom (1024 )
359
+ self .assertEqual (
360
+ b"cpu_load_short,host=server01,region=us-west "
361
+ b"value=0.64 1257894000\n " ,
362
+ received_data ,
363
+ )
364
+
365
+ cli .write_points (self .dummy_points , time_precision = 'm' )
366
+ received_data , addr = s .recvfrom (1024 )
367
+ self .assertEqual (
368
+ b'cpu_load_short,host=server01,region=us-west '
369
+ b'value=0.64 20964900\n ' ,
370
+ received_data ,
371
+ )
372
+
373
+ cli .write_points (self .dummy_points , time_precision = 'h' )
374
+ received_data , addr = s .recvfrom (1024 )
375
+ self .assertEqual (
376
+ b'cpu_load_short,host=server01,region=us-west '
377
+ b'value=0.64 349415\n ' ,
378
+ received_data ,
379
+ )
380
+
338
381
def test_write_points_bad_precision (self ):
339
382
"""Test write points w/bad precision TestInfluxDBClient object."""
340
383
cli = InfluxDBClient ()
0 commit comments