func TestHandlerReconnects(t *testing.T) {
	ctrl := gomock.NewController(t)
	defer ctrl.Finish()
	taskEngine := mock_engine.NewMockTaskEngine(ctrl)
	ecsclient := mock_api.NewMockECSClient(ctrl)
	statemanager := statemanager.NewNoopStateManager()

	closeWS := make(chan bool)
	server, serverIn, _, _, err := startMockAcsServer(t, closeWS)
	if err != nil {
		t.Fatal(err)
	}

	ecsclient.EXPECT().DiscoverPollEndpoint("myArn").Return(server.URL, nil).AnyTimes()
	taskEngine.EXPECT().Version().Return("Docker: 1.5.0", nil).AnyTimes()

	ended := make(chan bool, 1)
	go func() {
		handler.StartSession("myArn", credentials.NewCredentialProvider("", ""), &config.Config{Cluster: "someCluster"}, taskEngine, ecsclient, statemanager, true)
		// This should never return
		ended <- true
	}()
	start := time.Now()
	for i := 0; i < 10; i++ {
		serverIn <- `{"type":"HeartbeatMessage","message":{"healthy":true}}`
		closeWS <- true
	}
	if time.Since(start) > 2*time.Second {
		t.Error("Test took longer than expected; backoff should not have occured for EOF")
	}

	select {
	case <-ended:
		t.Fatal("Should never stop session")
	default:
	}
}
Esempio n. 2
0
	"strings"
	"testing"
	"time"
)

var (
	// from Amazon authv4 test suite
	region      = "us-east-1"
	service     = "host"
	accessKey   = "AKIDEXAMPLE"
	secretKey   = "wJalrXUtnFEMI/K7MDENG+bPxRfiCYEXAMPLEKEY"
	refdate     = "Mon, 09 Sep 2011 23:36:00 GMT"
	testdate, _ = time.Parse(time.RFC1123, refdate)
)

var creds = credentials.NewCredentialProvider(accessKey, secretKey)

// reads req file and creates an http request to match
func getTestReq(filename string) (*http.Request, []string, error) {

	reqtext, err := ioutil.ReadFile(filename)
	if err != nil {
		return nil, nil, err
	}

	reqarray := strings.Split(string(reqtext), "\n")

	// first line should be method and path
	first_line := strings.Split(reqarray[0], " ")
	method := strings.TrimSpace(first_line[0])
	path := strings.TrimSpace(first_line[1])