From e7cb6bd1765956d3d778cf9a3c1faa44a37df70d Mon Sep 17 00:00:00 2001 From: Yanislav Igonin Date: Wed, 18 May 2022 10:23:35 +0300 Subject: [PATCH] trying vegeta load testing --- .gitignore | 7 ++++++- db/db.go | 12 ++++++++---- repositories/seeds.go | 2 +- tests/load.sh | 6 +++++- 4 files changed, 20 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index 0181505..a2f635c 100644 --- a/.gitignore +++ b/.gitignore @@ -24,4 +24,9 @@ uploads/ .env -*.bin \ No newline at end of file +*.bin + +tests/metrics.json +tests/plot.html + +.DS_Store \ No newline at end of file diff --git a/db/db.go b/db/db.go index 240fc1d..fc0ad90 100644 --- a/db/db.go +++ b/db/db.go @@ -49,11 +49,11 @@ func Migrate() { if !isMigrationInDb { sql := Files.ReadFileText(m) runMigration(id, name, sql) - log.Println("database migration - " + name + " - online") + log.Println("migration - " + name + " - online") } } - log.Println("database migrations - online") + log.Println("migrations - online") } func runMigration(mid int, mname, msql string) { @@ -72,11 +72,11 @@ func runMigration(mid int, mname, msql string) { func getDbMigrations() MigrationsMap { sql := `SELECT id, name FROM migrations` rows, err := Pool.Query(context.TODO(), sql) - if err != nil { + if err != nil && isNotNonExistentMigrationsTable(err) { log.Panicln(err) } - if rows.Err() != nil { + if rows.Err() != nil && isNotNonExistentMigrationsTable(rows.Err()) { log.Panicln(rows.Err()) } @@ -93,3 +93,7 @@ func getDbMigrations() MigrationsMap { return migrationsMap } + +func isNotNonExistentMigrationsTable(err error) bool { + return err.Error() != `ERROR: relation "migrations" does not exist (SQLSTATE 42P01)` +} diff --git a/repositories/seeds.go b/repositories/seeds.go index e2b7be1..aea9148 100644 --- a/repositories/seeds.go +++ b/repositories/seeds.go @@ -111,5 +111,5 @@ func seedDb() { func Seed() { seedDb() - log.Println("mocks - online") + log.Println("seeds - online") } diff --git a/tests/load.sh b/tests/load.sh index d27a87a..d7abcf2 100755 --- a/tests/load.sh +++ b/tests/load.sh @@ -1 +1,5 @@ -autocannon localhost:3000 \ No newline at end of file + echo "GET https://micrach.igonin.dev" | vegeta attack -rate 100 -duration=120s | tee results.bin | vegeta report + # vegeta report -type=json results.bin > metrics.json + cat results.bin | vegeta plot > plot.html + open plot.html + # cat results.bin | vegeta report -type="hist[0,100ms,200ms,300ms]"