(ctx context.Context, args []string)
| 40 | } |
| 41 | |
| 42 | func (c *LoadCommand) Run(ctx context.Context, args []string) error { |
| 43 | fs := flag.NewFlagSet("litestream-test load", flag.ExitOnError) |
| 44 | fs.StringVar(&c.DB, "db", "", "Database path (required)") |
| 45 | fs.IntVar(&c.WriteRate, "write-rate", 100, "Writes per second") |
| 46 | fs.DurationVar(&c.Duration, "duration", 1*time.Minute, "How long to run") |
| 47 | fs.StringVar(&c.Pattern, "pattern", "constant", "Write pattern (constant, burst, random, wave)") |
| 48 | fs.IntVar(&c.PayloadSize, "payload-size", 1024, "Size of each write operation in bytes") |
| 49 | fs.Float64Var(&c.ReadRatio, "read-ratio", 0.2, "Read/write ratio (0.0-1.0)") |
| 50 | fs.IntVar(&c.Workers, "workers", 1, "Number of concurrent workers") |
| 51 | fs.Usage = c.Usage |
| 52 | if err := fs.Parse(args); err != nil { |
| 53 | return err |
| 54 | } |
| 55 | |
| 56 | if c.DB == "" { |
| 57 | return fmt.Errorf("database path required") |
| 58 | } |
| 59 | |
| 60 | if _, err := os.Stat(c.DB); err != nil { |
| 61 | return fmt.Errorf("database does not exist: %w", err) |
| 62 | } |
| 63 | |
| 64 | slog.Info("Starting load generation", |
| 65 | "db", c.DB, |
| 66 | "write_rate", c.WriteRate, |
| 67 | "duration", c.Duration, |
| 68 | "pattern", c.Pattern, |
| 69 | "payload_size", c.PayloadSize, |
| 70 | "read_ratio", c.ReadRatio, |
| 71 | "workers", c.Workers, |
| 72 | ) |
| 73 | |
| 74 | return c.generateLoad(ctx) |
| 75 | } |
| 76 | |
| 77 | func (c *LoadCommand) generateLoad(ctx context.Context) error { |
| 78 | db, err := sql.Open("sqlite3", c.DB+"?_journal_mode=WAL") |
nothing calls this directly
no test coverage detected