mirror of
https://github.com/weaveworks/scope.git
synced 2026-05-17 14:47:48 +00:00
* New encoding format:
* Msgpack reports between probe<->app (smaller representation, faster to
encode/decode).
* Still use JSON between app<->UI (try to avoid making javascript deal with
mspack).
The app still suports publishing reports in both gob and JSON, not braking
backwards compatibility.
* Use compile-time generated marshallers/unmarshallers for higher performance. In
order to be able to skip code-generation for certain types, I included
https://github.com/2opremio/go-1/tree/master/codec/codecgen instead of
upstream until https://github.com/ugorji/go/pull/139 is merged.
* Encode/decode intermediate types using github.com/ugorji/go/codec.Selfer
for higher performance and reducing garbage collection (no temporary buffers).
74 lines
1.5 KiB
Go
74 lines
1.5 KiB
Go
package app_test
|
|
|
|
import (
|
|
"net"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"strings"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/gorilla/mux"
|
|
"github.com/ugorji/go/codec"
|
|
|
|
"github.com/weaveworks/scope/app"
|
|
"github.com/weaveworks/scope/common/xfer"
|
|
"github.com/weaveworks/scope/probe/appclient"
|
|
)
|
|
|
|
func TestControl(t *testing.T) {
|
|
router := mux.NewRouter()
|
|
app.RegisterControlRoutes(router)
|
|
server := httptest.NewServer(router)
|
|
defer server.Close()
|
|
|
|
ip, port, err := net.SplitHostPort(strings.TrimPrefix(server.URL, "http://"))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
probeConfig := appclient.ProbeConfig{
|
|
ProbeID: "foo",
|
|
}
|
|
controlHandler := xfer.ControlHandlerFunc(func(req xfer.Request) xfer.Response {
|
|
if req.NodeID != "nodeid" {
|
|
t.Fatalf("'%s' != 'nodeid'", req.NodeID)
|
|
}
|
|
|
|
if req.Control != "control" {
|
|
t.Fatalf("'%s' != 'control'", req.Control)
|
|
}
|
|
|
|
return xfer.Response{
|
|
Value: "foo",
|
|
}
|
|
})
|
|
client, err := appclient.NewAppClient(probeConfig, ip+":"+port, ip+":"+port, controlHandler)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
client.ControlConnection()
|
|
defer client.Stop()
|
|
|
|
time.Sleep(100 * time.Millisecond)
|
|
|
|
httpClient := http.Client{
|
|
Timeout: 1 * time.Second,
|
|
}
|
|
resp, err := httpClient.Post(server.URL+"/api/control/foo/nodeid/control", "", nil)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
defer resp.Body.Close()
|
|
|
|
var response xfer.Response
|
|
decoder := codec.NewDecoder(resp.Body, &codec.JsonHandle{})
|
|
if err := decoder.Decode(&response); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
if response.Value != "foo" {
|
|
t.Fatalf("'%s' != 'foo'", response.Value)
|
|
}
|
|
}
|