Skip to content
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

test: more robust test #2041

Merged
merged 1 commit into from
Oct 20, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 29 additions & 10 deletions pkg/functions/client_int_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -454,20 +454,39 @@ func Handle(ctx context.Context, res http.ResponseWriter, req *http.Request) {
package function

import (
"context"
"net/http"
"bytes"
"context"
"fmt"
"io"
"net/http"
"os"
"time"
)

func Handle(ctx context.Context, res http.ResponseWriter, req *http.Request) {
r, err := http.Get("http://localhost:3500/v1.0/invoke/a/method/")
if err != nil {
fmt.Printf("unable to invoke function a", err)
http.Error(res, "unable to invoke function a", http.StatusServiceUnavailable)
func Handle(ctx context.Context, w http.ResponseWriter, req *http.Request) {
var e error
var r *http.Response
var buff bytes.Buffer
var out io.Writer = io.MultiWriter(os.Stderr, &buff)
for i := 0; i < 10; i++ {
r, e = http.Get("http://localhost:3500/v1.0/invoke/a/method/")
if e != nil {
_, _ = fmt.Fprintf(out, "unable to invoke function a: %v\n", e)
time.Sleep(time.Second*3)
continue
}
defer r.Body.Close()
if r.StatusCode != 200 {
_, _ = fmt.Fprintf(out, "bad http status code when invoking a: %d\n", r.StatusCode)
time.Sleep(time.Second*3)
continue
}
w.WriteHeader(200)
_, _ = io.Copy(w, r.Body)
return
}
defer r.Body.Close()
io.Copy(res,r.Body)
http.Error(w, fmt.Sprintf("unable to invoke function a:\n%s", buff.String()), http.StatusServiceUnavailable)
return
}
`
os.WriteFile(filepath.Join(root, "handle.go"), []byte(source), os.ModePerm)
Expand All @@ -488,7 +507,7 @@ func Handle(ctx context.Context, res http.ResponseWriter, req *http.Request) {
fmt.Printf("### function a response body: %s\n", body)

if string(body) != "TestInvoke_ServiceToService OK" {
t.Fatalf("Unexpected response from Function B: %v", body)
t.Fatalf("Unexpected response from Function B: %v", string(body))
}
}

Expand Down
Loading