diff --git a/Makefile b/Makefile index 19a6daa..6b6bd11 100644 --- a/Makefile +++ b/Makefile @@ -110,6 +110,10 @@ test-fuzz: export DL_SKIP_SSL_VERIFICATION=1 test-fuzz: reset-db go run cmd/fuzz-test/main.go --host $(GRPC_HOST) --iterations 1000 --projects 5 +bench: export DB_URI = postgres://$(DB_USER):$(DB_PASS)@$(DB_HOST):5432/dl_tests +bench: migrate + cd test && go test -bench . -run=^# + reset-db: migrate psql $(DB_URI) -c "truncate dl.objects; truncate dl.contents; truncate dl.projects; truncate dl.cache_versions;" diff --git a/test/hardlink_dir_benchmark_test.go b/test/hardlink_dir_benchmark_test.go new file mode 100644 index 0000000..bd02aeb --- /dev/null +++ b/test/hardlink_dir_benchmark_test.go @@ -0,0 +1,25 @@ +package test + +import ( + "fmt" + "os" + "path" + "testing" + + "github.com/gadget-inc/dateilager/internal/files" +) + +func BenchmarkHardlinkDir(b *testing.B) { + wd, err := os.Getwd() + if err != nil { + b.Error(err) + } + + bigDir := path.Join(wd, "../node_modules") + tmpDir := emptyTmpDir(b) + defer os.RemoveAll(tmpDir) + + for n := 0; n < b.N; n++ { + files.HardlinkDir(bigDir, path.Join(tmpDir, "node_modules", fmt.Sprintf("%d", n))) + } +} diff --git a/test/shared_test.go b/test/shared_test.go index 640e023..21e0a3c 100644 --- a/test/shared_test.go +++ b/test/shared_test.go @@ -274,9 +274,11 @@ func writeFile(t *testing.T, dir string, path string, content string) { require.NoError(t, err, "write file %v", path) } -func emptyTmpDir(t *testing.T) string { +func emptyTmpDir(t testing.TB) string { dir, err := os.MkdirTemp("", "dateilager_tests_") - require.NoError(t, err, "create temp dir") + if err != nil { + t.Fatal(err) + } return dir }