File tree Expand file tree Collapse file tree 1 file changed +23
-2
lines changed
reader/src/test/java/org/jline/reader/impl Expand file tree Collapse file tree 1 file changed +23
-2
lines changed Original file line number Diff line number Diff line change @@ -42,8 +42,29 @@ public void testPasswordMaskingWithDumbTerminal() throws IOException {
42
42
assertTrue (output .contains ("Password: " ));
43
43
44
44
// The output should contain multiple instances of the prompt due to the masking thread
45
- int promptCount = countOccurrences (output , "Password: " );
46
- assertTrue (promptCount > 1 , "Expected multiple instances of the prompt due to masking thread" );
45
+ // Add a delay to ensure the masking thread has time to run
46
+ // The masking thread in LineReaderImpl runs every 3ms, so we need to wait
47
+ // long enough for multiple refreshes to occur
48
+ int promptCount = 0 ;
49
+ long startTime = System .currentTimeMillis ();
50
+ long timeout = 500 ; // 500ms should be plenty of time
51
+
52
+ while (promptCount <= 1 && (System .currentTimeMillis () - startTime ) < timeout ) {
53
+ try {
54
+ Thread .sleep (50 );
55
+ } catch (InterruptedException e ) {
56
+ // Ignore
57
+ }
58
+
59
+ // Get the output again after the delay
60
+ output = out .toString ();
61
+ promptCount = countOccurrences (output , "Password: " );
62
+ }
63
+
64
+ assertTrue (
65
+ promptCount > 1 ,
66
+ "Expected multiple instances of the prompt due to masking thread. " + "Prompt count: " + promptCount
67
+ + ", Output: " + output );
47
68
}
48
69
}
49
70
You can’t perform that action at this time.
0 commit comments