|
| 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 | +} |
0 commit comments