Example #1
0
func testServerReceive(t *testing.T) {
	wg := &sync.WaitGroup{}
	lookup := make(map[string]string)

	for i := 0; i < 10; i++ {
		wg.Add(1)
		go func() {
			defer wg.Done()

			ctx, cancel := context.WithTimeout(context.Background(), config.ClusterRequestTimeout)
			if r, err := api.Request(ctx, ":"+strconv.Itoa(config.Port), &api.ReceiveRequest{topic}); err != nil {
				if grpc.Code(err) == codes.NotFound {
					return
				}
				cancel()
				t.Error(err)
			} else {
				fmt.Println(r)
				resp := r.(*api.ReceiveResponse)
				if v, b := lookup[resp.Key]; b {
					t.Errorf("Msg: %v already exists: %v\n", resp, v)
				}
				lookup[resp.Key] = string(resp.Msg)
			}
		}()
	}
	wg.Wait()
}
Example #2
0
func testServerSend(t *testing.T) {
	wg := &sync.WaitGroup{}

	for i := 0; i < 10; i++ {
		wg.Add(1)
		go func(cnt int) {
			defer wg.Done()

			ctx, cancel := context.WithTimeout(context.Background(), config.ClusterRequestTimeout)
			msg := strconv.Itoa(cnt)
			_, err := api.Request(ctx, ":"+strconv.Itoa(config.Port), &api.SendRequest{topic, []byte(msg)})
			if err != nil {
				cancel()
				t.Error(err)
			}
		}(i)
	}
	wg.Wait()
}