func RunListTrendingArtists(c crowdsound.CrowdSoundClient, amount int) (metrics.Histogram, error) { h := metrics.NewHistogram(metrics.NewUniformSample(amount)) // To make trending artists meaningful, add a bunch of artists. postStream, err := c.PostSong(context.Background()) if err != nil { return h, err } for song := range songGenerator(100, 1.0) { song.UserId = randomString(32) if err = postStream.Send(song); err != nil { return h, err } } if _, err = postStream.CloseAndRecv(); err != nil { return h, err } for i := 0; i < amount; i++ { start := time.Now() listStream, err := c.ListTrendingArtists(context.Background(), &crowdsound.ListTrendingArtistsRequest{}) if err != nil { return h, err } for { _, err := listStream.Recv() if err == io.EOF { break } if err != nil { log.Fatal(err) } } h.Update(time.Since(start).Nanoseconds()) } return h, nil }