-
-
Notifications
You must be signed in to change notification settings - Fork 952
Improve ShellStream Expect #1315
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve ShellStream Expect #1315
Conversation
@Rob-Hague Can I ask for a review? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks
I have nearly fixed the remaining tests
@Rob-Hague Thanks! I haven't touched the other tests and I won't. |
@@ -471,6 +475,7 @@ public IAsyncResult BeginExpect(TimeSpan timeout, AsyncCallback callback, object | |||
if (match.Success) | |||
{ | |||
var result = text.Substring(0, match.Index + match.Length); | |||
var charCount = _encoding.GetByteCount(result); | |||
|
|||
for (var i = 0; i < match.Index + match.Length && _incoming.Count > 0; i++) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this line use charCount?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I fixed it in my PR.
Btw, working on ShellStream makes me wish it derived from StreamReader rather than Stream... it would save a lot of repeated encoding work for the Expect methods (and just make more sense in general). But perhaps not worth the break. |
I believe that ShellStream still has it's place, however perhaps a new ShellStreamReader could be added that would consume the a ShellStream and we could slowly migrate functionality between the two classes. It could even be done in two steps. First by adding the new methods into ShellStreamReader, and then later deprecating them on ShellStream. |
This issue has been fixed in the 2024.0.0 version. |
There are three implementation of Expect method:
Two of them return string ends with the expected expression.
Only the first one works differently. In this PR I fixed this problem.
Moreover, the _incoming array contains bytes and regex works on UTF8 encoding, so we should count how many bytes we should remove from the incoming array.
Continuation of #1313
Added test failures for #1207 (does not fix performance issue)