@@ -385,6 +385,47 @@ def test_constructor_rejects_a_missing_blank_or_overlong_version(self):
385385 TraceClient (self .base_url , "MyGame" , "9" * MAX_TAG_LENGTH , enabled = False )
386386 TraceClient (self .base_url , "MyGame" , " " + "9" * MAX_TAG_LENGTH + " " , enabled = False )
387387
388+ def test_constructor_errors_name_the_argument_they_reject (self ):
389+ overlong = "x" * (MAX_TAG_LENGTH + 1 )
390+ cases = (
391+ ("base_url" , lambda : TraceClient (" " , "MyGame" , "1.2.3" )),
392+ ("application" , lambda : TraceClient (self .base_url , "" , "1.2.3" )),
393+ ("version" , lambda : TraceClient (self .base_url , "MyGame" , " " )),
394+ ("version" , lambda : TraceClient (self .base_url , "MyGame" , overlong )),
395+ ("install_id" , lambda : TraceClient (self .base_url , "MyGame" , "1.2.3" , install_id = overlong )),
396+ )
397+ for argument , construct in cases :
398+ with self .assertRaises (ValueError ) as raised :
399+ construct ()
400+ self .assertTrue (str (raised .exception ).startswith (argument + " " ),
401+ "the only raising path should say which argument was wrong: %s" % raised .exception )
402+ with self .assertRaises (ValueError ) as raised :
403+ TraceClient (self .base_url , "MyGame" , overlong )
404+ self .assertIn (str (MAX_TAG_LENGTH ), str (raised .exception ), "an overlong value names the limit" )
405+
406+ def test_the_sender_is_one_daemon_thread_named_after_the_application (self ):
407+ before = set (threading .enumerate ())
408+ client = TraceClient (self .base_url , " MyGame " , "1.2.3" , key = "k" )
409+ try :
410+ started = [t for t in threading .enumerate () if t not in before ]
411+ self .assertEqual (1 , len (started ), "one sender thread per client" )
412+ sender = started [0 ]
413+ self .assertTrue (sender .daemon , "a daemon thread never keeps the host program from exiting" )
414+ self .assertEqual ("trace-client/MyGame" , sender .name , "named after the trimmed application" )
415+ finally :
416+ client .close ()
417+ self .assertFalse (sender .is_alive (), "close() stops it" )
418+
419+ def test_a_disabled_client_starts_no_thread (self ):
420+ before = set (threading .enumerate ())
421+ clients = (TraceClient (self .base_url , "MyGame" , "1.2.3" , key = "k" , enabled = False ),
422+ TraceClient (self .base_url , "MyGame" , "1.2.3" ),
423+ TraceClient .disabled ())
424+ started = [t for t in threading .enumerate () if t not in before ]
425+ self .assertEqual ([], started , "a disabled client costs nothing" )
426+ for client in clients :
427+ client .close ()
428+
388429 def test_report_tags_a_command_with_the_program_version_trimmed (self ):
389430 client = TraceClient (self .base_url , "MyGame" , " 2.0.0-SNAPSHOT " , key = "k" )
390431 client .report ("command" , tags = {"name" : "home" })
0 commit comments