tag1consulting / goose

Load testing framework, inspired by Locust
https://tag1.com/goose
Apache License 2.0
737 stars 67 forks source link

panic: assertion failed: self.is_char_boundary(new_len) when transaction!(xx).set_name("一二三四五六七") #567

Closed kirito41dd closed 8 months ago

kirito41dd commented 8 months ago
thread 'main' panicked at 'assertion failed: self.is_char_boundary(new_len)', /rustc/8ede3aae28fe6e4d52b38157d7bfe0d3bceef225/library/alloc/src/string.rs:1279:13
stack backtrace:
   0: rust_begin_unwind
             at /rustc/8ede3aae28fe6e4d52b38157d7bfe0d3bceef225/library/std/src/panicking.rs:593:5
   1: core::panicking::panic_fmt
             at /rustc/8ede3aae28fe6e4d52b38157d7bfe0d3bceef225/library/core/src/panicking.rs:67:14
   2: core::panicking::panic
             at /rustc/8ede3aae28fe6e4d52b38157d7bfe0d3bceef225/library/core/src/panicking.rs:117:5
   3: goose::util::truncate_string
   4: <goose::metrics::GooseMetrics as core::fmt::Display>::fmt
   5: core::fmt::rt::Argument::fmt
             at /rustc/8ede3aae28fe6e4d52b38157d7bfe0d3bceef225/library/core/src/fmt/rt.rs:138:9
   6: core::fmt::write
             at /rustc/8ede3aae28fe6e4d52b38157d7bfe0d3bceef225/library/core/src/fmt/mod.rs:1094:21
   7: std::io::Write::write_fmt
             at /rustc/8ede3aae28fe6e4d52b38157d7bfe0d3bceef225/library/std/src/io/mod.rs:1713:15
   8: <&std::io::stdio::Stdout as std::io::Write>::write_fmt
             at /rustc/8ede3aae28fe6e4d52b38157d7bfe0d3bceef225/library/std/src/io/stdio.rs:726:9
   9: <std::io::stdio::Stdout as std::io::Write>::write_fmt
             at /rustc/8ede3aae28fe6e4d52b38157d7bfe0d3bceef225/library/std/src/io/stdio.rs:700:9
  10: std::io::stdio::print_to
             at /rustc/8ede3aae28fe6e4d52b38157d7bfe0d3bceef225/library/std/src/io/stdio.rs:1018:21
  11: std::io::stdio::_print
             at /rustc/8ede3aae28fe6e4d52b38157d7bfe0d3bceef225/library/std/src/io/stdio.rs:1095:5
  12: tokio::park::thread::CachedParkThread::block_on
  13: tokio::runtime::thread_pool::ThreadPool::block_on
  14: tokio::runtime::Runtime::block_on
  15: goosetest::main
kirito41dd commented 8 months ago

It seems because the name is too long

jeremyandrews commented 8 months ago

This looks to be because the truncate_string() helper function is naively assuming utf-8.

Some relevant discussion here which should make this possible to fix: https://stackoverflow.com/questions/38461429/how-can-i-truncate-a-string-to-have-at-most-n-characters