Skip to content

Commit

Permalink
add delay
Browse files Browse the repository at this point in the history
  • Loading branch information
wconti27 committed Jul 13, 2023
1 parent bd640f1 commit 8c3073d
Show file tree
Hide file tree
Showing 19 changed files with 106 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ func New() *Integration {
return &Integration{}
}

func (i *Integration) ResetNumSpans() {
i.numSpans = 0
}

func (i *Integration) Name() string {
return "contrib/bradfitz/gomemcache/memcache"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ func New() *Integration {
return &Integration{}
}

func (i *Integration) ResetNumSpans() {
i.numSpans = 0
}

func (i *Integration) Name() string {
return "contrib/garyburd/redigo"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ func (i *Integration) NumSpans() int {
return i.numSpans
}

func (i *Integration) ResetNumSpans() {
i.numSpans = 0
}

var entity = bson.D{
bson.DocElem{
Name: "entity_new",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ func New() *Integration {
return &Integration{}
}

func (i *Integration) ResetNumSpans() {
i.numSpans = 0
}

func (i *Integration) Name() string {
return "contrib/go-pg/pg.v10"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ func New() *Integration {
return &Integration{}
}

func (i *Integration) ResetNumSpans() {
i.numSpans = 0
}

func (i *Integration) Name() string {
return "contrib/go-redis/redis.v7"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ func New() *Integration {
return &Integration{}
}

func (i *Integration) ResetNumSpans() {
i.numSpans = 0
}

func (i *Integration) Name() string {
return "contrib/go-redis/redis.v8"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ func New() *Integration {
return &Integration{}
}

func (i *Integration) ResetNumSpans() {
i.numSpans = 0
}

func (i *Integration) Name() string {
return "contrib/go-redis/redis"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ func New() *Integration {
return &Integration{}
}

func (i *Integration) ResetNumSpans() {
i.numSpans = 0
}

func (i *Integration) Name() string {
return "contrib/go.mongodb.org/mongo-driver/mongo"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ func New() *Integration {
return &Integration{}
}

func (i *Integration) ResetNumSpans() {
i.numSpans = 0
}

func (i *Integration) Name() string {
return "contrib/gocql/gocql"
}
Expand Down Expand Up @@ -51,15 +55,15 @@ func (i *Integration) Init(t *testing.T) func() {
func (i *Integration) GenSpans(t *testing.T) {
t.Helper()
q := i.session.Query("SELECT * from trace.person")
gocqltrace.WrapQuery(q, gocqltrace.WithServiceName("TestServiceName")).Exec()
gocqltrace.WrapQuery(q).Exec()
q2 := i.session.Query("SELECT * from trace.person")
gocqltrace.WrapQuery(q2, gocqltrace.WithServiceName("TestServiceName")).Exec()
gocqltrace.WrapQuery(q2).Exec()
q3 := i.session.Query("SELECT * from trace.person")
gocqltrace.WrapQuery(q3, gocqltrace.WithServiceName("TestServiceName")).Exec()
gocqltrace.WrapQuery(q3).Exec()
i.numSpans += 3

b := i.session.NewBatch(gocql.UnloggedBatch)
tb := gocqltrace.WrapBatch(b, gocqltrace.WithServiceName("TestServiceName"), gocqltrace.WithResourceName("BatchInsert"))
tb := gocqltrace.WrapBatch(b)

stmt := "INSERT INTO trace.person (name, age, description) VALUES (?, ?, ?)"
tb.Query(stmt, "Kate", 80, "Cassandra's sister running in kubernetes")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ func New() *Integration {
return &Integration{}
}

func (i *Integration) ResetNumSpans() {
i.numSpans = 0
}

func (i *Integration) Name() string {
return "contrib/garyburd/redigo"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@ func (i *Integration) Name() string {

func (i *Integration) Init(t *testing.T) func() {
t.Helper()
defer sqltest.Prepare(gormtest.TableName)()
return func() {}
close_func := sqltest.Prepare(gormtest.TableName)

Check failure on line 37 in contrib/internal/validationtest/contrib/gopkg.in/jinzhu/gorm.v1/integration.go

View workflow job for this annotation

GitHub Actions / PR Unit and Integration Tests / lint

var-naming: don't use underscores in Go names; var close_func should be closeFunc (revive)

Check failure on line 37 in contrib/internal/validationtest/contrib/gopkg.in/jinzhu/gorm.v1/integration.go

View workflow job for this annotation

GitHub Actions / PR Unit and Integration Tests / lint

var-naming: don't use underscores in Go names; var close_func should be closeFunc (revive)
return func() {
close_func()
}
}

func (i *Integration) GenSpans(t *testing.T) {
Expand All @@ -46,6 +48,10 @@ func (i *Integration) NumSpans() int {
return i.numSpans
}

func (i *Integration) ResetNumSpans() {
i.numSpans = 0
}

func registerFunc(driverName string, driver driver.Driver) {
sqltrace.Register(driverName, driver)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@ func (i *Integration) Name() string {

func (i *Integration) Init(t *testing.T) func() {
t.Helper()
defer sqltest.Prepare(gormtest.TableName)()
return func() {}
close_func := sqltest.Prepare(gormtest.TableName)

Check failure on line 37 in contrib/internal/validationtest/contrib/jinzhu/gorm/integration.go

View workflow job for this annotation

GitHub Actions / PR Unit and Integration Tests / lint

var-naming: don't use underscores in Go names; var close_func should be closeFunc (revive)

Check failure on line 37 in contrib/internal/validationtest/contrib/jinzhu/gorm/integration.go

View workflow job for this annotation

GitHub Actions / PR Unit and Integration Tests / lint

var-naming: don't use underscores in Go names; var close_func should be closeFunc (revive)
return func() {
close_func()
}
}

func (i *Integration) GenSpans(t *testing.T) {
Expand All @@ -55,6 +57,5 @@ func getDB(driverName string, connString string, _ func(*sql.DB) gorm.Dialector)
if err != nil {
log.Fatal(err)
}
defer db.Close()
return db.DB()
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,20 @@
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2016 Datadog, Inc.

package sqlx
package gorm

import (
"database/sql"
"database/sql/driver"
"log"
"testing"

_ "github.com/lib/pq"
gormtest "gopkg.in/DataDog/dd-trace-go.v1/contrib/internal/validationtest/contrib/shared/gorm"
sqltest "gopkg.in/DataDog/dd-trace-go.v1/contrib/internal/validationtest/contrib/shared/sql"
"gorm.io/gorm"

sqltrace "gopkg.in/DataDog/dd-trace-go.v1/contrib/database/sql"
gormtrace "gopkg.in/DataDog/dd-trace-go.v1/contrib/gopkg.in/jinzhu/gorm.v1"
sqlxtrace "gopkg.in/DataDog/dd-trace-go.v1/contrib/jmoiron/sqlx"
)

type Integration struct {
Expand All @@ -29,7 +28,7 @@ func New() *Integration {
}

func (i *Integration) Name() string {
return "contrib/gopkg.in/jinzhu/gorm.v1"
return "contrib/jmoiron/sqlx"
}

func (i *Integration) Init(t *testing.T) func() {
Expand All @@ -50,11 +49,11 @@ func registerFunc(driverName string, driver driver.Driver) {
sqltrace.Register(driverName, driver)
}

func getDB(driverName string, connString string, dialectorFunc func(*sql.DB) gorm.Dialector) *sql.DB {
db, err := gormtrace.Open(driverName, connString)
func getDB(driverName string, connString string, _ func(*sql.DB) gorm.Dialector) *sql.DB {
db, err := sqlxtrace.Open(driverName, connString)
if err != nil {
log.Fatal(err)
}
defer db.Close()
return db.DB()
return db.DB
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ func New() *Integration {
return &Integration{}
}

func (i *Integration) ResetNumSpans() {
i.numSpans = 0
}

func (i *Integration) Name() string {
return "contrib/redis/go-redis.v9"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@ import (

"github.com/go-sql-driver/mysql"
"github.com/jackc/pgx/v5/stdlib"
mssql "github.com/microsoft/go-mssqldb"
sqltest "gopkg.in/DataDog/dd-trace-go.v1/contrib/internal/validationtest/contrib/shared/sql"
mysqlgorm "gorm.io/driver/mysql"
"gorm.io/driver/postgres"
"gorm.io/driver/sqlserver"
"gorm.io/gorm"
)

Expand Down Expand Up @@ -40,13 +38,13 @@ func RunAll(numSpans int, t *testing.T, registerFunc func(string, driver.Driver)
driver: &stdlib.Driver{},
dialectorFunc: func(sqlDB *sql.DB) gorm.Dialector { return mysqlgorm.New(mysqlgorm.Config{Conn: sqlDB}) },
},
{
name: "SQLServer",
connString: sqlServerConnString,
driverName: "sqlserver",
driver: &mssql.Driver{},
dialectorFunc: func(sqlDB *sql.DB) gorm.Dialector { return sqlserver.New(sqlserver.Config{Conn: sqlDB}) },
},
// {
// name: "SQLServer",
// connString: sqlServerConnString,
// driverName: "sqlserver",
// driver: &mssql.Driver{},
// dialectorFunc: func(sqlDB *sql.DB) gorm.Dialector { return sqlserver.New(sqlserver.Config{Conn: sqlDB}) },
// },
{
name: "MySQL",
connString: mysqlConnString,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,30 +26,33 @@ func Prepare(tableName string) func() {
queryDrop := fmt.Sprintf("DROP TABLE IF EXISTS %s", tableName)
queryCreate := fmt.Sprintf("CREATE TABLE %s (id integer NOT NULL DEFAULT '0', name text)", tableName)
mysql, err := sql.Open("mysql", "test:test@tcp(127.0.0.1:3306)/test")
defer mysql.Close()
if err != nil {
log.Fatal(err)
}
mysql.Exec(queryDrop)
mysql.Exec(queryCreate)

postgres, err := sql.Open("postgres", "postgres://postgres:postgres@127.0.0.1:5432/postgres?sslmode=disable")
defer postgres.Close()
if err != nil {
log.Fatal(err)
}
postgres.Exec(queryDrop)
postgres.Exec(queryCreate)

// mssql, err := sql.Open("sqlserver", "sqlserver://sa:myPassw0rd@localhost:1433?database=master")
// defer mssql.Close()
// if err != nil {
// log.Fatal(err)
// }
// mssql.Exec(queryDrop)
// mssql.Exec(queryCreate)

return func() {
mysql.Exec(queryDrop)
postgres.Exec(queryDrop)
//mssql.Exec(queryDrop)
mysql.Close()
postgres.Close()
// mssql.Close()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ func New() *Integration {
return &Integration{}
}

func (i *Integration) ResetNumSpans() {
i.numSpans = 0
}

func (i *Integration) Name() string {
return "contrib/syndtr/goleveldb/leveldb"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ func New() *Integration {
return &Integration{}
}

func (i *Integration) ResetNumSpans() {
i.numSpans = 0
}

func (i *Integration) Name() string {
return "contrib/tidwall/buntdb"
}
Expand Down
Loading

0 comments on commit 8c3073d

Please sign in to comment.