test: add new startNewREPLSever
testing utility
#59964
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR adds a new testing utility called
startNewREPLSever
which simply starts a new repl server that can be used for testing.The reasoning for proposing this change are to reduce unnecessary code repetition (notice that the PR is net removing more than 450 lines of code1) and to also provide some consistency on how repl server are tested.
Currently in tests when a new repl server gets started some input/output streams need to be passed to it, sometimes they are implemented via
new stream.PassThrough()
, some other times (more commonly) vianew ArrayStream()
, sometimes a single stream is passed both as the input and output, sometimes different streams are passed instead.In most cases (as far as I can tell) there isn't a specific reason as to why an implementation has been chosen or not.
startNewREPLSever
removes this variation by adopting what looked to me like the most commonly used implementation aspects.Another nice thing is that
startNewREPLSever
helps with variable name consistency. Currently when a test repl server is started it is stored in a variable which name can ber
,replServer
,server
ortestMe
. Input streams can beinput
,putIn
orinputStream
. Output streams can beoutput
,putIn
oroutputStream
. (I am likely forgetting some variation too).startNewREPLSever
consistently refers to these values respectively asreplServer
,input
andoutput
.Please note that my PR is not replacing all repl server starts in tests with
startNewREPLSever
, mainly because sometimes that is not helpful (for example when testing the repl constructor default values) or because it would require some involved refactoring (and I think that this PR is pretty big as it is 😅, if this lands I can also see as a followup ifstartNewREPLSever
could, be used in a few other tests as well)Footnotes
The output accumulation logic is re-implemented multiple times as well as the error domain on error handler logic. ↩