Skip to content

Commit d37898f

Browse files
authored
Add standalone test (#122)
1 parent c43817c commit d37898f

File tree

6 files changed

+126
-8
lines changed

6 files changed

+126
-8
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Gemfile.lock
1414
vendor/
1515
jaeger-ui-build/
1616
examples/hotrod/hotrod*
17-
cmd/standalone/standalone*
17+
cmd/standalone/standalone-linux
1818
cmd/agent/agent*
1919
cmd/collector/collector*
2020
cmd/query/query*

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ clean:
5151
test: go-gen
5252
$(GOTEST) $(PACKAGES) | $(COLORIZE)
5353

54+
.PHONY: integration-test
55+
integration-test: go-gen
56+
$(GOTEST) -tags=integration ./cmd/standalone/...
57+
5458
.PHONY: fmt
5559
fmt:
5660
$(GOFMT) -e -s -l -w $(ALL_SRC)

cmd/standalone/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,14 @@ import (
2929
"strconv"
3030

3131
"github.com/gorilla/mux"
32+
jaegerClientConfig "github.com/uber/jaeger-client-go/config"
3233
"github.com/uber/jaeger-lib/metrics"
3334
"github.com/uber/jaeger-lib/metrics/go-kit"
3435
"github.com/uber/jaeger-lib/metrics/go-kit/expvar"
3536
"github.com/uber/tchannel-go"
3637
"github.com/uber/tchannel-go/thrift"
3738
"go.uber.org/zap"
3839

39-
jaegerClientConfig "github.com/uber/jaeger-client-go/config"
4040
agentApp "github.com/uber/jaeger/cmd/agent/app"
4141
basic "github.com/uber/jaeger/cmd/builder"
4242
collector "github.com/uber/jaeger/cmd/collector/app/builder"

cmd/standalone/standalone_test.go

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
// Copyright (c) 2017 Uber Technologies, Inc.
2+
//
3+
// Permission is hereby granted, free of charge, to any person obtaining a copy
4+
// of this software and associated documentation files (the "Software"), to deal
5+
// in the Software without restriction, including without limitation the rights
6+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
// copies of the Software, and to permit persons to whom the Software is
8+
// furnished to do so, subject to the following conditions:
9+
//
10+
// The above copyright notice and this permission notice shall be included in
11+
// all copies or substantial portions of the Software.
12+
//
13+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19+
// THE SOFTWARE.
20+
21+
// +build integration
22+
23+
package main
24+
25+
import (
26+
"encoding/json"
27+
"fmt"
28+
"io/ioutil"
29+
"net/http"
30+
"testing"
31+
"time"
32+
33+
"github.com/stretchr/testify/require"
34+
35+
ui "github.com/uber/jaeger/model/json"
36+
)
37+
38+
const (
39+
host = "0.0.0.0"
40+
queryPort = "16686"
41+
queryHostPort = host + ":" + queryPort
42+
queryURL = "http://" + queryHostPort
43+
44+
getServicesURL = queryURL + "/api/services"
45+
getTraceURL = queryURL + "/api/traces?service=jaeger-query&tag=jaeger-debug-id:debug"
46+
)
47+
48+
var (
49+
httpClient = &http.Client{
50+
Timeout: time.Second,
51+
}
52+
)
53+
54+
func TestStandalone(t *testing.T) {
55+
// Check if the query service is available
56+
if err := healthCheck(); err != nil {
57+
t.Fatal(err)
58+
}
59+
60+
createTrace(t)
61+
getAPITrace(t)
62+
}
63+
64+
func createTrace(t *testing.T) {
65+
req, err := http.NewRequest("GET", getServicesURL, nil)
66+
require.NoError(t, err)
67+
req.Header.Add("jaeger-debug-id", "debug")
68+
69+
resp, err := httpClient.Do(req)
70+
require.NoError(t, err)
71+
resp.Body.Close()
72+
}
73+
74+
type response struct {
75+
Data []*ui.Trace `json:"data"`
76+
}
77+
78+
func getAPITrace(t *testing.T) {
79+
req, err := http.NewRequest("GET", getTraceURL, nil)
80+
require.NoError(t, err)
81+
82+
var queryResponse response
83+
84+
for i := 0; i < 20; i++ {
85+
resp, err := httpClient.Do(req)
86+
require.NoError(t, err)
87+
88+
body, _ := ioutil.ReadAll(resp.Body)
89+
90+
err = json.Unmarshal(body, &queryResponse)
91+
require.NoError(t, err)
92+
resp.Body.Close()
93+
94+
if len(queryResponse.Data) == 1 {
95+
break
96+
}
97+
time.Sleep(time.Second)
98+
}
99+
require.Len(t, queryResponse.Data, 1)
100+
require.Len(t, queryResponse.Data[0].Spans, 1)
101+
}
102+
103+
func healthCheck() error {
104+
for i := 0; i < 100; i++ {
105+
if _, err := http.Get(queryURL); err == nil {
106+
return nil
107+
}
108+
time.Sleep(100 * time.Millisecond)
109+
}
110+
return fmt.Errorf("query service is not ready")
111+
}

glide.lock

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

travis/build-all-in-one-image.sh

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,12 @@ make build-all-in-one-linux
99
export REPO=jaegertracing/all-in-one
1010
export BRANCH=$(if [ "$TRAVIS_PULL_REQUEST" == "false" ]; then echo $TRAVIS_BRANCH; else echo $TRAVIS_PULL_REQUEST_BRANCH; fi)
1111

12+
docker build -f cmd/standalone/Dockerfile -t $REPO:$COMMIT .
13+
export CID=$(docker run -d -p 16686:16686 $REPO:$COMMIT)
14+
make integration-test
15+
docker kill $CID
16+
1217
# Only push the docker container to Docker Hub for master branch
1318
if [ "$BRANCH" == "master" ]; then echo 'upload to Docker Hub'; else echo 'skip docker upload for PR'; exit 0; fi
1419

15-
docker build -f cmd/standalone/Dockerfile -t $REPO:$COMMIT .
16-
1720
bash ./travis/upload-to-docker.sh

0 commit comments

Comments
 (0)