コード例 #1
0
// GetServerTime calls the GetTime method of the messaging, parses the response to get the
// value and return it.
func GetServerTime(c context.Context, w http.ResponseWriter, r *http.Request, pubnubInstance *messaging.Pubnub, t *testing.T, testName string) int64 {
	returnTimeChannel := make(chan []byte)
	errorChannel := make(chan []byte)

	//go pubnubInstance.GetTime(returnTimeChannel, errorChannel)
	go pubnubInstance.GetTime(c, w, r, returnTimeChannel, errorChannel)
	return ParseServerTimeResponse(returnTimeChannel, t, testName)
}
コード例 #2
0
// PublishMessages calls the publish method of messaging package numberOfMessages times
// and appends the count with the message to distinguish from the others.
//
// Parameters:
// pubnubInstance: a reference of *messaging.Pubnub,
// channel: the pubnub channel to publish the messages,
// t: a reference to *testing.T,
// startMessagesFrom: the message identifer,
// numberOfMessages: number of messages to send,
// message: message to send.
//
// returns a bool if the publish of all messages is successful.
func PublishMessages(context context.Context, w http.ResponseWriter, r *http.Request, pubnubInstance *messaging.Pubnub, channel string, t *testing.T, startMessagesFrom int, numberOfMessages int, message string) bool {
	messagesReceived := 0
	messageToSend := ""
	tOut := messaging.GetNonSubscribeTimeout()
	messaging.SetNonSubscribeTimeout(30)
	for i := startMessagesFrom; i < startMessagesFrom+numberOfMessages; i++ {
		messageToSend = message + strconv.Itoa(i)

		returnPublishChannel := make(chan []byte)
		errorChannel := make(chan []byte)
		go pubnubInstance.Publish(context, w, r, channel, messageToSend, returnPublishChannel, errorChannel)

		messagesReceived++
		//time.Sleep(500 * time.Millisecond)
		time.Sleep(1500 * time.Millisecond)
	}
	if messagesReceived == numberOfMessages {
		return true
	}
	messaging.SetNonSubscribeTimeout(tOut)
	return false
}