This is an automated email from the ASF dual-hosted git repository.
csantanapr pushed a commit to branch master
in repository
https://gitbox.apache.org/repos/asf/incubator-openwhisk-runtime-go.git
The following commit(s) were added to refs/heads/master by this push:
new 535a253 Fix random failures (#37)
535a253 is described below
commit 535a2531dd4848f45f2e4bb2f265b5986a7655b6
Author: Sciabarra.com ltd <[email protected]>
AuthorDate: Tue May 22 03:01:02 2018 +0200
Fix random failures (#37)
---
.gitignore | 1 +
README.md | 1 +
openwhisk/actionProxy_linux_test.go | 71 -------------------------------------
openwhisk/actionProxy_test.go | 41 +++++++++++++++++++++
openwhisk/executor.go | 15 ++++----
openwhisk/initHandler_linux_test.go | 44 -----------------------
openwhisk/initHandler_test.go | 19 ++++++++++
openwhisk/util_test.go | 2 ++
8 files changed, 73 insertions(+), 121 deletions(-)
diff --git a/.gitignore b/.gitignore
index 445f1e6..5b0205c 100644
--- a/.gitignore
+++ b/.gitignore
@@ -39,3 +39,4 @@ tests/bin/
*.class
*.iml
tests/out/
+
diff --git a/README.md b/README.md
index 6729558..b3666a5 100644
--- a/README.md
+++ b/README.md
@@ -179,3 +179,4 @@ done
```
Note the `actionloop` image will accept any source and will try to run it (if
it is possible), while the `actionloop-golang` and `actionloop-swift` images
will try to compile the sources instead.
+
diff --git a/openwhisk/actionProxy_linux_test.go
b/openwhisk/actionProxy_linux_test.go
deleted file mode 100644
index d131713..0000000
--- a/openwhisk/actionProxy_linux_test.go
+++ /dev/null
@@ -1,71 +0,0 @@
-// +build linux
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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.
- */
-
-/*
-This test depends on the fact the proxy can detect the termination
-of an executable that terminates before or after reading the output.
-On OSX command termination is not detected until some input is read.
-*/
-
-package openwhisk
-
-import (
- "io/ioutil"
- "os"
- "testing"
-
- "github.com/stretchr/testify/assert"
-)
-
-func TestStartLatestAction(t *testing.T) {
-
- // cleanup
- os.RemoveAll("./action")
- logf, _ := ioutil.TempFile("/tmp", "log")
- ap := NewActionProxy("./action", "", logf)
-
- // start an action that terminate immediately
- buf := []byte("#!/bin/sh\ntrue\n")
- ap.ExtractAction(&buf, "main")
- ap.StartLatestAction("main")
- assert.Nil(t, ap.theExecutor)
-
- // start the action that emits 1
- buf = []byte("#!/bin/sh\nwhile read a; do echo 1 >&3 ; done\n")
- ap.ExtractAction(&buf, "main")
- ap.StartLatestAction("main")
- ap.theExecutor.io <- "x"
- assert.Equal(t, <-ap.theExecutor.io, "1")
-
- // now start an action that terminate immediately
- buf = []byte("#!/bin/sh\ntrue\n")
- ap.ExtractAction(&buf, "main")
- ap.StartLatestAction("main")
- ap.theExecutor.io <- "y"
- assert.Equal(t, <-ap.theExecutor.io, "1")
-
- // start the action that emits 2
- buf = []byte("#!/bin/sh\nwhile read a; do echo 2 >&3 ; done\n")
- ap.ExtractAction(&buf, "main")
- ap.StartLatestAction("main")
- ap.theExecutor.io <- "z"
- assert.Equal(t, <-ap.theExecutor.io, "2")
- /**/
- ap.theExecutor.Stop()
-}
diff --git a/openwhisk/actionProxy_test.go b/openwhisk/actionProxy_test.go
index e639edb..23c18e3 100644
--- a/openwhisk/actionProxy_test.go
+++ b/openwhisk/actionProxy_test.go
@@ -19,6 +19,11 @@ package openwhisk
import (
"fmt"
+ "io/ioutil"
+ "os"
+ "testing"
+
+ "github.com/stretchr/testify/assert"
)
func Example_startTestServer() {
@@ -38,3 +43,39 @@ func Example_startTestServer() {
// {"error":"no action defined yet"}
// {"error":"Error unmarshaling request: invalid character 'X' looking
for beginning of value"}
}
+func TestStartLatestAction(t *testing.T) {
+
+ // cleanup
+ os.RemoveAll("./action")
+ logf, _ := ioutil.TempFile("/tmp", "log")
+ ap := NewActionProxy("./action", "", logf)
+
+ // start an action that terminate immediately
+ buf := []byte("#!/bin/sh\ntrue\n")
+ ap.ExtractAction(&buf, "main")
+ ap.StartLatestAction("main")
+ assert.Nil(t, ap.theExecutor)
+
+ // start the action that emits 1
+ buf = []byte("#!/bin/sh\nwhile read a; do echo 1 >&3 ; done\n")
+ ap.ExtractAction(&buf, "main")
+ ap.StartLatestAction("main")
+ ap.theExecutor.io <- "x"
+ assert.Equal(t, <-ap.theExecutor.io, "1")
+
+ // now start an action that terminate immediately
+ buf = []byte("#!/bin/sh\ntrue\n")
+ ap.ExtractAction(&buf, "main")
+ ap.StartLatestAction("main")
+ ap.theExecutor.io <- "y"
+ assert.Equal(t, <-ap.theExecutor.io, "1")
+
+ // start the action that emits 2
+ buf = []byte("#!/bin/sh\nwhile read a; do echo 2 >&3 ; done\n")
+ ap.ExtractAction(&buf, "main")
+ ap.StartLatestAction("main")
+ ap.theExecutor.io <- "z"
+ assert.Equal(t, <-ap.theExecutor.io, "2")
+ /**/
+ ap.theExecutor.Stop()
+}
diff --git a/openwhisk/executor.go b/openwhisk/executor.go
index 160aea3..3f29eee 100644
--- a/openwhisk/executor.go
+++ b/openwhisk/executor.go
@@ -27,9 +27,11 @@ import (
"time"
)
-// TIMEOUT to wait for process to start
-// and log to be produced
-const TIMEOUT = 5 * time.Millisecond
+// DefaultTimeoutInit to wait for a process to start
+var DefaultTimeoutInit = 5 * time.Millisecond
+
+// DefaultTimeoutDrain to wait for draining logs
+var DefaultTimeoutDrain = 5 * time.Millisecond
// Executor is the container and the guardian of a child process
// It starts a command, feeds input and output, read logs and control its
termination
@@ -110,12 +112,12 @@ func (proc *Executor) run() {
}
func (proc *Executor) drain(ch chan string) {
- runtime.Gosched()
for loop := true; loop; {
+ runtime.Gosched()
select {
case buf := <-ch:
fmt.Fprintln(proc._logbuf, buf)
- case <-time.After(TIMEOUT):
+ case <-time.After(DefaultTimeoutDrain):
loop = false
}
}
@@ -139,6 +141,7 @@ func (proc *Executor) logger() {
// flush stderr
proc.drain(chErr)
}
+ proc._logbuf.Sync()
log.Printf("logger: end")
}
@@ -180,7 +183,7 @@ func (proc *Executor) Start() error {
case <-proc.exit:
// oops, it died
return fmt.Errorf("command exited")
- case <-time.After(TIMEOUT):
+ case <-time.After(DefaultTimeoutInit):
// ok let's process it
go proc.service()
go proc.logger()
diff --git a/openwhisk/initHandler_linux_test.go
b/openwhisk/initHandler_linux_test.go
deleted file mode 100644
index 0d40a38..0000000
--- a/openwhisk/initHandler_linux_test.go
+++ /dev/null
@@ -1,44 +0,0 @@
-// +build linux
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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.
- */
-
-/*
-This test depends on the fact the proxy can detect the termination
-of an executable that terminates before or after reading the output.
-On OSX command termination is not detected until some input is read.
-*/
-package openwhisk
-
-func Example_badinit_nocompiler() {
- ts, cur, log := startTestServer("")
- doRun(ts, "")
- doInit(ts, "{}")
- //sys("ls", "_test/exec")
- doInit(ts, initBinary("_test/exec", "")) // empty
- doInit(ts, initBinary("_test/hi", "")) // say hi
- doInit(ts, initBinary("_test/hello.src", "")) // source not excutable
- doRun(ts, "")
- stopTestServer(ts, cur, log)
- // Output:
- // 400 {"error":"no action defined yet"}
- // 200 {"ok":true}
- // 400 {"error":"cannot start action: command exited"}
- // 400 {"error":"cannot start action: command exited"}
- // 400 {"error":"cannot start action: command exited"}
- // 400 {"error":"no action defined yet"}
-}
diff --git a/openwhisk/initHandler_test.go b/openwhisk/initHandler_test.go
index aaf30db..cdb2add 100644
--- a/openwhisk/initHandler_test.go
+++ b/openwhisk/initHandler_test.go
@@ -231,3 +231,22 @@ func Example_compile_withZipSrcDefault() {
// XXX_THE_END_OF_A_WHISK_ACTIVATION_XXX
}
/**/
+
+func Example_badinit_nocompiler() {
+ ts, cur, log := startTestServer("")
+ doRun(ts, "")
+ doInit(ts, "{}")
+ //sys("ls", "_test/exec")
+ doInit(ts, initBinary("_test/exec", "")) // empty
+ doInit(ts, initBinary("_test/hi", "")) // say hi
+ doInit(ts, initBinary("_test/hello.src", "")) // source not excutable
+ doRun(ts, "")
+ stopTestServer(ts, cur, log)
+ // Output:
+ // 400 {"error":"no action defined yet"}
+ // 200 {"ok":true}
+ // 400 {"error":"cannot start action: command exited"}
+ // 400 {"error":"cannot start action: command exited"}
+ // 400 {"error":"cannot start action: command exited"}
+ // 400 {"error":"no action defined yet"}
+}
diff --git a/openwhisk/util_test.go b/openwhisk/util_test.go
index 18110be..190e61d 100644
--- a/openwhisk/util_test.go
+++ b/openwhisk/util_test.go
@@ -165,6 +165,8 @@ func detect(dir, filename string) string {
func TestMain(m *testing.M) {
sys("_test/build.sh")
sys("_test/zips.sh")
+ // increase timeouts
+ DefaultTimeoutInit = 1000 * time.Millisecond
code := m.Run()
os.Exit(code)
}
--
To stop receiving notification emails like this one, please contact
[email protected].