Skip to content
This repository has been archived by the owner on Sep 7, 2021. It is now read-only.
This repository is currently being migrated. It's locked while the migration is in progress.

Commit

Permalink
add redis cache ci tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lunny committed Jul 30, 2019
1 parent 73a7003 commit a8871f9
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 10 deletions.
17 changes: 17 additions & 0 deletions .drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ services:
when:
event: [ push, tag, pull_request ]

redis:
image: redis:3.0

#mssql:
# image: microsoft/mssql-server-linux:2017-CU11
# environment:
Expand Down Expand Up @@ -55,12 +58,21 @@ pipeline:
psql -U postgres -d xorm_test -h pgsql \
-c "create schema xorm;"
init_redis:
image: redis:3.0
commands:
- sleep 5
- redis-cli -h redis ping
- redis-cli -h redis set HELLO hello
- redis-cli -h redis get HELLO

build:
image: golang:${GO_VERSION}
commands:
- go get -t -d -v ./...
- go get -u xorm.io/core
- go get -u xorm.io/builder
- go get -u github.com/go-xorm/xorm-redis-cache
- go build -v
when:
event: [ push, pull_request ]
Expand All @@ -71,6 +83,7 @@ pipeline:
- go get -u github.com/wadey/gocovmerge
- go test -v -race -db="sqlite3" -conn_str="./test.db" -coverprofile=coverage1-1.txt -covermode=atomic
- go test -v -race -db="sqlite3" -conn_str="./test.db" -cache=true -coverprofile=coverage1-2.txt -covermode=atomic
- go test -v -race -db="sqlite3" -conn_str="./test.db" -cache=true -cache_redis_server="redis:6379" -coverprofile=coverage1-2.txt -covermode=atomic
when:
event: [ push, pull_request ]

Expand All @@ -79,6 +92,7 @@ pipeline:
commands:
- go test -v -race -db="mysql" -conn_str="root:@tcp(mysql)/xorm_test" -coverprofile=coverage2-1.txt -covermode=atomic
- go test -v -race -db="mysql" -conn_str="root:@tcp(mysql)/xorm_test" -cache=true -coverprofile=coverage2-2.txt -covermode=atomic
- go test -v -race -db="mysql" -conn_str="root:@tcp(mysql)/xorm_test" -cache=true -cache_redis_server="redis:6379" -coverprofile=coverage2-2.txt -covermode=atomic
when:
event: [ push, pull_request ]

Expand All @@ -95,6 +109,7 @@ pipeline:
commands:
- go test -v -race -db="mymysql" -conn_str="tcp:mysql:3306*xorm_test/root/" -coverprofile=coverage3-1.txt -covermode=atomic
- go test -v -race -db="mymysql" -conn_str="tcp:mysql:3306*xorm_test/root/" -cache=true -coverprofile=coverage3-2.txt -covermode=atomic
- go test -v -race -db="mymysql" -conn_str="tcp:mysql:3306*xorm_test/root/" -cache=true -cache_redis_server="redis:6379" -coverprofile=coverage3-2.txt -covermode=atomic
when:
event: [ push, pull_request ]

Expand All @@ -103,6 +118,7 @@ pipeline:
commands:
- go test -v -race -db="postgres" -conn_str="postgres://postgres:@pgsql/xorm_test?sslmode=disable" -coverprofile=coverage4-1.txt -covermode=atomic
- go test -v -race -db="postgres" -conn_str="postgres://postgres:@pgsql/xorm_test?sslmode=disable" -cache=true -coverprofile=coverage4-2.txt -covermode=atomic
- go test -v -race -db="postgres" -conn_str="postgres://postgres:@pgsql/xorm_test?sslmode=disable" -cache=true -cache_redis_server="redis:6379" -coverprofile=coverage4-2.txt -covermode=atomic
when:
event: [ push, pull_request ]

Expand All @@ -111,6 +127,7 @@ pipeline:
commands:
- go test -v -race -db="postgres" -conn_str="postgres://postgres:@pgsql/xorm_test?sslmode=disable" -schema=xorm -coverprofile=coverage5-1.txt -covermode=atomic
- go test -v -race -db="postgres" -conn_str="postgres://postgres:@pgsql/xorm_test?sslmode=disable" -schema=xorm -cache=true -coverprofile=coverage5-2.txt -covermode=atomic
- go test -v -race -db="postgres" -conn_str="postgres://postgres:@pgsql/xorm_test?sslmode=disable" -schema=xorm -cache=true -cache_redis_server="redis:6379" -coverprofile=coverage5-2.txt -covermode=atomic
- gocovmerge coverage1-1.txt coverage1-2.txt coverage2-1.txt coverage2-2.txt coverage2.1-1.txt coverage2.1-2.txt coverage3-1.txt coverage3-2.txt coverage4-1.txt coverage4-2.txt coverage5-1.txt coverage5-2.txt > coverage.txt
when:
event: [ push, pull_request ]
Expand Down
1 change: 1 addition & 0 deletions interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ type EngineInterface interface {
GetTableMapper() core.IMapper
GetTZDatabase() *time.Location
GetTZLocation() *time.Location
Logger() core.ILogger
MapCacher(interface{}, core.Cacher) error
NewSession() *Session
NoAutoTime() *Session
Expand Down
26 changes: 16 additions & 10 deletions xorm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,15 @@ var (
dbType string
connString string

db = flag.String("db", "sqlite3", "the tested database")
showSQL = flag.Bool("show_sql", true, "show generated SQLs")
ptrConnStr = flag.String("conn_str", "./test.db?cache=shared&mode=rwc", "test database connection string")
mapType = flag.String("map_type", "snake", "indicate the name mapping")
cache = flag.Bool("cache", false, "if enable cache")
cluster = flag.Bool("cluster", false, "if this is a cluster")
splitter = flag.String("splitter", ";", "the splitter on connstr for cluster")
schema = flag.String("schema", "", "specify the schema")
db = flag.String("db", "sqlite3", "the tested database")
showSQL = flag.Bool("show_sql", true, "show generated SQLs")
ptrConnStr = flag.String("conn_str", "./test.db?cache=shared&mode=rwc", "test database connection string")
mapType = flag.String("map_type", "snake", "indicate the name mapping")
cache = flag.Bool("cache", false, "if enable cache")
cacheRedisServer = flag.String("cache_redis_server", "127.0.0.1:6379", "if cache enabled this will enable redis cache mode")
cluster = flag.Bool("cluster", false, "if this is a cluster")
splitter = flag.String("splitter", ";", "the splitter on connstr for cluster")
schema = flag.String("schema", "", "specify the schema")
ignoreSelectUpdate = flag.Bool("ignore_select_update", false, "ignore select update if implementation difference, only for tidb")
)

Expand Down Expand Up @@ -106,8 +107,13 @@ func createEngine(dbType, connStr string) error {
testEngine.ShowSQL(*showSQL)
testEngine.SetLogLevel(core.LOG_DEBUG)
if *cache {
cacher := NewLRUCacher(NewMemoryStore(), 100000)
testEngine.SetDefaultCacher(cacher)
if *cacheRedisServer == "" {
cacher := NewLRUCacher(NewMemoryStore(), 100000)
testEngine.SetDefaultCacher(cacher)
} else {
cacher := xormrediscache.NewRedisCacher(*cacheRedisServer, "", xormrediscache.DEFAULT_EXPIRATION, testEngine.Logger())
testEngine.SetDefaultCacher(cacher)
}
}

if len(*mapType) > 0 {
Expand Down

0 comments on commit a8871f9

Please sign in to comment.