nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: sqlc-dev/sqlc
Pull request #2750 (2023-09-20 20:54:09)

test(endtoend): Pull region from environment


Patch:
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 75661b766..6fe347097 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -55,8 +55,6 @@ jobs:
       with:
         go-version: '1.21.1'
 
-    - run: curl -I https://debug.fly.dev
-
     - name: install gotestsum
       run: go install gotest.tools/gotestsum@latest
 
diff --git a/internal/quickdb/region.go b/internal/quickdb/region.go
new file mode 100644
index 000000000..bc03e3b3f
--- /dev/null
+++ b/internal/quickdb/region.go
@@ -0,0 +1,19 @@
+package quickdb
+
+import (
+	"net/http"
+	"sync"
+)
+
+var region string
+var once sync.Once
+
+func GetClosestRegion() string {
+	once.Do(func() {
+		resp, err := http.Get("https://debug.fly.dev")
+		if err == nil {
+			region = resp.Header.Get("Fly-Region")
+		}
+	})
+	return region
+}


Test patch:
diff --git a/internal/endtoend/ddl_test.go b/internal/endtoend/ddl_test.go
index 33085926a..123a503ce 100644
--- a/internal/endtoend/ddl_test.go
+++ b/internal/endtoend/ddl_test.go
@@ -23,6 +23,7 @@ func TestValidSchema(t *testing.T) {
 
 	projectID := os.Getenv("CI_SQLC_PROJECT_ID")
 	authToken := os.Getenv("CI_SQLC_AUTH_TOKEN")
+
 	if projectID == "" || authToken == "" {
 		if os.Getenv("CI") == "" {
 			t.Skip("skiping ddl tests outside of CI")
@@ -106,11 +107,11 @@ func TestValidSchema(t *testing.T) {
 
 				resp, err := client.CreateEphemeralDatabase(ctx, &pb.CreateEphemeralDatabaseRequest{
 					Engine:     "postgresql",
-					Region:     "iad",
+					Region:     quickdb.GetClosestRegion(),
 					Migrations: sqls,
 				})
 				if err != nil {
-					t.Fatal(err)
+					t.Fatalf("region %s: %s", quickdb.GetClosestRegion(), err)
 				}
 
 				t.Cleanup(func() {
diff --git a/internal/sqltest/hosted/db.go b/internal/sqltest/hosted/db.go
index c7829a607..4d2fe8dc8 100644
--- a/internal/sqltest/hosted/db.go
+++ b/internal/sqltest/hosted/db.go
@@ -58,11 +58,11 @@ func PostgreSQL(t *testing.T, migrations []string) string {
 
 	resp, err := client.CreateEphemeralDatabase(ctx, &pb.CreateEphemeralDatabaseRequest{
 		Engine:     "postgresql",
-		Region:     "iad",
+		Region:     quickdb.GetClosestRegion(),
 		Migrations: seed,
 	})
 	if err != nil {
-		t.Fatal(err)
+		t.Fatalf("region %s: %s", quickdb.GetClosestRegion(), err)
 	}
 
 	t.Cleanup(func() {