コード例 #1
0
ファイル: packet_smoke_test.go プロジェクト: jrconlin/pushgo
func (t caseTest) TestPing() error {
	origin, err := testServer.Origin()
	if err != nil {
		return fmt.Errorf("On test %v, error initializing test server: %#v", t.CaseTestType, err)
	}
	conn, err := client.DialOrigin(origin)
	if err != nil {
		return fmt.Errorf("On test %v, error dialing origin: %#v", t.CaseTestType, err)
	}
	defer conn.Close()
	defer conn.Purge()
	conn.RegisterDecoder("ping", client.DecoderFunc(decodePing))
	request := CaseClientPing{t.CaseTestType, client.NewPing(true)}
	reply, err := conn.WriteRequest(request)
	if err != nil {
		return fmt.Errorf("On test %v, error writing ping packet: %#v", t.CaseTestType, err)
	}
	if reply.Status() != t.statusCode {
		return fmt.Errorf("On test %v, unexpected status code: got %#v; want %#v", t.CaseTestType, reply.Status(), t.statusCode)
	}
	return nil
}
コード例 #2
0
ファイル: api_smoke_test.go プロジェクト: jrconlin/pushgo
func TestPing(t *testing.T) {
	origin, err := testServer.Origin()
	if err != nil {
		t.Fatalf("Error initializing test server: %#v", err)
	}
	conn, _, err := client.Dial(origin)
	if err != nil {
		t.Fatalf("Error dialing origin: %#v", err)
	}
	defer conn.Close()
	defer conn.Purge()
	conn.RegisterDecoder("ping", client.DecoderFunc(decodePing))
	var pingWait sync.WaitGroup
	writePing := func() {
		defer pingWait.Done()
		reply, err := conn.WriteRequest(client.NewPing(true))
		if err != nil {
			t.Errorf("Error writing ping request: %#v", err)
			return
		}
		if reply.Status() != 200 {
			t.Errorf("Unexpected ping reply status code: got %#v; want 200", reply.Status())
		}
	}
	writeRegister := func() {
		defer pingWait.Done()
		channelId, endpoint, err := conn.Subscribe()
		if err != nil {
			t.Errorf("Error subscribing to channel: %#v", err)
		}
		if !isValidEndpoint(endpoint) {
			t.Errorf("Invalid push endpoint for channel %#v: %#v", channelId, endpoint)
		}
	}
	pingWait.Add(2)
	go writeRegister()
	go writePing()
	pingWait.Wait()
}