(ctx context.Context, latencyCh chan int64, failureCount *int64)
| 220 | } |
| 221 | |
| 222 | func (p *perf) generateTraffic(ctx context.Context, latencyCh chan int64, failureCount *int64) { |
| 223 | limiter := rate.NewLimiter(rate.Limit(p.config.RequestRate), int(p.config.RequestRate)) |
| 224 | |
| 225 | count := 0 |
| 226 | for { |
| 227 | if err := limiter.Wait(ctx); err != nil { |
| 228 | return |
| 229 | } |
| 230 | c := count |
| 231 | count++ |
| 232 | person := Person{Name: "rbt", Money: c, Expected: c + 1} |
| 233 | jsonBytes, err := json.Marshal(person) |
| 234 | if err != nil { |
| 235 | slog.Error( |
| 236 | "Failed to marshal Person", |
| 237 | slog.Any("error", err), |
| 238 | ) |
| 239 | os.Exit(1) |
| 240 | } |
| 241 | start := time.Now() |
| 242 | if !common.SendToChannel(ctx, p.input, contube.NewRecordImpl(jsonBytes, func() {})) { |
| 243 | return |
| 244 | } |
| 245 | go func() { |
| 246 | e, ok := common.ReceiveFromChannel(ctx, p.output) |
| 247 | if !ok { |
| 248 | return |
| 249 | } |
| 250 | latencyCh <- time.Since(start).Microseconds() |
| 251 | payload := e.GetPayload() |
| 252 | e.Commit() |
| 253 | var out Person |
| 254 | err = json.Unmarshal(payload, &out) |
| 255 | if err != nil { |
| 256 | slog.Error( |
| 257 | "Failed to unmarshal Person", |
| 258 | slog.Any("error", err), |
| 259 | slog.Any("payload", payload), |
| 260 | ) |
| 261 | os.Exit(1) |
| 262 | } |
| 263 | if out.Money != out.Expected { |
| 264 | slog.Error( |
| 265 | "Unexpected value for money", |
| 266 | slog.Any("money", out.Money), |
| 267 | ) |
| 268 | atomic.AddInt64(failureCount, 1) |
| 269 | } |
| 270 | }() |
| 271 | } |
| 272 | } |
no test coverage detected