Skip to content

WFCORE-7623: signal if input is idle#6860

Open
michpetrov wants to merge 1 commit into
wildfly:mainfrom
michpetrov:wfcore-7623-2
Open

WFCORE-7623: signal if input is idle#6860
michpetrov wants to merge 1 commit into
wildfly:mainfrom
michpetrov:wfcore-7623-2

Conversation

@michpetrov

Copy link
Copy Markdown
Contributor

Issue: WFCORE-7623
Follow-up to #6849

Since the wrapper is using blocking IO we can only guess if the input will be idle, but as far as I can see we can reliably tell if we're in the "waiting for user input" state, and only check the prompt at that point. This should prevent the tests from failing with a partially printed output, assuming whatever is happening on Windows is simply a timing issue.

private Process cliProcess;
private volatile StringBuffer cliOutputBuffer = new StringBuffer();
private BufferedWriter bufferedWriter = null;
private boolean idleInput = false;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This variable must be volatile, otherwise there will not be visibility guarantees between the three threads that modify/read it

public String getCurrentPrompt(){
if(cliOutputBuffer.toString().contains("\n")) {
return cliOutputBuffer.toString().substring(cliOutputBuffer.toString().lastIndexOf("\n")+1);
return cliOutputBuffer.substring(cliOutputBuffer.toString().lastIndexOf("\n")+1);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please always apply the standard code formatting, otherwise in the future applying the format will generate changes

Comment on lines 181 to +182
if(cliOutputBuffer.toString().contains("\n")) {
return cliOutputBuffer.toString().substring(cliOutputBuffer.toString().lastIndexOf("\n")+1);
return cliOutputBuffer.substring(cliOutputBuffer.toString().lastIndexOf("\n")+1);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What hapends if after reading"cliOutputBuffer.toString().contains("\n")" the cliOutputBuffer changes in between before executing the return?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The method is called after we made sure the buffer shouldn't be changing. But even if it changed it should still be returning the last line of the output, worse case lastIndexOf("\n")+1 is 0.

Comment on lines +320 to +325
if (!br.ready()) {
idleInput = idleCounter <= 1;
idleCounter++;
} else {
idleInput = false;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not get the behaviour of this logic. Could you explain it here? , why "idleCounter <= 1" and why you do it if the buffer is not ready?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand the process will echo the user input, and here what you want to do is to signal when this echo has not finished yet. Also, I understand that the server output is processed as an stream, and I guess this is the main issue.

Correct me if I am wrong, each echo will be following by a new line, and in that moment the output of the command result will start, probably it will contain several lines.

I do not get how this will help with this:

https://github.com/michpetrov/wildfly-core/blob/wfcore-7623-2/testsuite/shared/src/main/java/org/jboss/as/test/integration/management/cli/CliProcessWrapper.java#L232

which seems to be the main issue since outputHasPrompt could be invoked after the input was echoed by the server but the full command output is not fully processed yet.

Would not be easier to use a producer consumer pattern on the threads that reads the std out / err and produce line by line?, consumers will wait until a line is ready, consumers will not read lines in the middle of processing. In general, looks like that sharing the cliOutputBuffer between the CliResultsReader threads and the main thread is quite problematic

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants