Skip to content

Commit

Permalink
Add test client works when server closes output stream
Browse files Browse the repository at this point in the history
  • Loading branch information
jvican committed Jun 27, 2019
1 parent ad35340 commit 367cc5f
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
38 changes: 38 additions & 0 deletions core/src/test/java/sailgun/utils/SailgunStatusCode.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
Copyright 2004-2012, Martian Software, Inc.
Copyright 2017-Present Facebook, Inc
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package sailgun.utils;

import com.martiansoftware.nailgun.NGContext;

/** Finish nail with provided exit code */
public class SailgunStatusCode {
public static void nailMain(NGContext ctx) {
String[] args = ctx.getArgs();
int exitCode = (int) ((Math.random() * 1000) + 1);
if (args.length > 0) {
try {
exitCode = Integer.parseInt(args[0]);
} catch (Exception e) {
}
}
// Close stdout to test the exit code is returned properly
// even in such case
System.out.close();
ctx.exit(exitCode);
}
}
6 changes: 6 additions & 0 deletions core/src/test/scala/sailgun/SailgunSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ object SailgunSpec extends SailgunBaseSuite {
)
}

testSailgun("closing stdout in nail doesn't affect client") { inputs =>
val code = inputs.run("sailgun.utils.SailgunStatusCode", Array("0"))
assert(code == 0)
assertNoDiff(inputs.output, "")
}

val echoStdout = new PipedOutputStream()
val echoStdin = new PipedInputStream(echoStdout)
testSailgun("echo works (via stdin)", echoStdin) { inputs =>
Expand Down

0 comments on commit 367cc5f

Please sign in to comment.