Esempio n. 1
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(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(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
}
Esempio n. 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(pubnubInstance *messaging.Pubnub, channel string,
	t *testing.T, startMessagesFrom int, numberOfMessages int,
	message string, sleep func(int)) bool {

	assert := assert.New(t)
	messagesReceived := 0
	messageToSend := ""
	tOut := messaging.GetNonSubscribeTimeout()
	messaging.SetNonSubscribeTimeout(30)

	successChannel := make(chan []byte)
	errorChannel := make(chan []byte)

	for i := startMessagesFrom; i < startMessagesFrom+numberOfMessages; i++ {
		messageToSend = message + strconv.Itoa(i)

		go pubnubInstance.Publish(channel, messageToSend, successChannel, errorChannel)
		select {
		case <-successChannel:
			messagesReceived++
		case err := <-errorChannel:
			assert.Fail("Failed to get channel list", string(err))
		case <-messaging.Timeout():
			assert.Fail("WhereNow timeout")
		}
	}

	sleep(3)
	if messagesReceived == numberOfMessages {
		return true
	}

	messaging.SetNonSubscribeTimeout(tOut)

	return false
}
Esempio n. 3
0
func main() {
	// messaging.SetLogOutput(os.Stderr)
	pubnub = messaging.NewPubnub(PubKey, SubKey, SecKey, "", false, "")
	messaging.SetNonSubscribeTimeout(2)

	send := make(chan string, 40)
	receive := make(chan string, 40)
	done := make(chan bool, 2)
	sync := make(chan bool)

	grant()

	go subscribeWorker(receive)
	go synchronizer(sync)

	for i := 0; i < workers; i++ {
		go worker(i, send, sync)
	}

	go func() {
		for j := 0; j < workers*multiplier; j++ {
			fmt.Printf(">>> %d: %s\n", j, <-send)
		}
		done <- true
	}()

	go func() {
		for k := 0; k < workers*multiplier; k++ {
			fmt.Printf("<<< %d: %s\n", k, <-receive)
		}
		done <- true
	}()

	<-done
	<-done
}