Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
庄润梓 committed Jun 28, 2024
1 parent e5b6383 commit 5bc5328
Showing 1 changed file with 60 additions and 0 deletions.
60 changes: 60 additions & 0 deletions tests/e2e/greptimedbcluster_baremetal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,16 @@
package e2e

import (
"context"
"database/sql"
"fmt"
"io"
"net"
"os"
"os/exec"
"time"

"github.com/go-sql-driver/mysql"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)
Expand Down Expand Up @@ -76,6 +79,63 @@ var _ = Describe("Basic test of greptimedb cluster in baremetal", func() {
GinkgoWriter.Printf("failed to terminated the process\n")
}

By("Connecting GreptimeDB")
var db *sql.DB
var conn *sql.Conn

Eventually(func() error {
cfg := mysql.Config{
Net: "tcp",
Addr: "127.0.0.1:4002",
User: "",
Passwd: "",
DBName: "",
AllowNativePasswords: true,
}

db, err = sql.Open("mysql", cfg.FormatDSN())
if err != nil {
return err
}

conn, err = db.Conn(context.TODO())
if err != nil {
return err
}

return nil
}, 30*time.Second, time.Second).ShouldNot(HaveOccurred())

By("Execute SQL queries after connecting")

ctx, cancel := context.WithTimeout(context.Background(), defaultQueryTimeout)
defer cancel()

_, err = conn.ExecContext(ctx, createTableSQL)
Expect(err).NotTo(HaveOccurred(), "failed to create SQL table")

ctx, cancel = context.WithTimeout(context.Background(), defaultQueryTimeout)
defer cancel()
for rowID := 1; rowID <= testRowIDNum; rowID++ {
insertDataSQL := fmt.Sprintf(insertDataSQLStr, rowID, rowID)
_, err = conn.ExecContext(ctx, insertDataSQL)
Expect(err).NotTo(HaveOccurred(), "failed to insert data")
}

ctx, cancel = context.WithTimeout(context.Background(), defaultQueryTimeout)
defer cancel()
results, err := conn.QueryContext(ctx, selectDataSQL)
Expect(err).NotTo(HaveOccurred(), "failed to get data")

var data []TestData
for results.Next() {
var d TestData
err = results.Scan(&d.timestamp, &d.n, &d.rowID)
Expect(err).NotTo(HaveOccurred(), "failed to scan data that query from db")
data = append(data, d)
}
Expect(len(data) == testRowIDNum).Should(BeTrue(), "get the wrong data from db")

err = deleteClusterinBaremetal()
Expect(err).NotTo(HaveOccurred(), "failed to delete cluster in baremetal")
})
Expand Down

0 comments on commit 5bc5328

Please sign in to comment.