-
Notifications
You must be signed in to change notification settings - Fork 162
[POC] CSGHub server integration testing framework #283
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Yiling-J
wants to merge
38
commits into
main
Choose a base branch
from
oss/integration_tests
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
38 commits
Select commit
Hold shift + click to select a range
7956a85
init integration test framework
Yiling-J edc0eb3
add simple model integration test
Yiling-J df36bf7
fix tests and update CI
Yiling-J 3824cb1
fix ci
Yiling-J 0f2ef97
fix test
Yiling-J 782acb6
fix integration test
Yiling-J a702055
test
Yiling-J 6ef2565
fix github ci
Yiling-J 1bf3656
fix gitaly test config
Yiling-J 47635b0
fix typo
Yiling-J 5286481
add model git integration test
Yiling-J e9acdfd
fix integration tests start/shutdown
Yiling-J 61db145
fix test
Yiling-J e5ac22a
debug
Yiling-J e5ac634
debug
Yiling-J f8656c8
debug
Yiling-J dd9e149
debug
Yiling-J 6b84c34
fix integration test git commit
Yiling-J 786c350
remove debug info
Yiling-J e7b3f07
add local s3 to integration test env and test lfs
Yiling-J 34252d4
remove unused comment
Yiling-J d2b2043
add dataset workflow integration test
Yiling-J edf8908
fix lint
Yiling-J 4b58838
validate integration test flaky
Yiling-J 1fba932
fix ci
Yiling-J d57c07c
update
Yiling-J f7d86a4
remove not working yaml
Yiling-J 78519d6
update dataset viewer integration test
Yiling-J 24c7b6e
update dataset viewer integration test
Yiling-J 9c6ebd3
update model integration CRUD test
Yiling-J 8f5f515
add test readme
Yiling-J d4398dc
add run_test_server command
Yiling-J cdccb02
update readme
Yiling-J c887c59
update readme
Yiling-J 02a9f91
update readme
Yiling-J 47c64fe
update readme
Yiling-J 1786607
update dataset viewer workflow test
Yiling-J adc8769
update readme
Yiling-J File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,6 +51,10 @@ type Operator struct { | |
Core bun.IDB | ||
} | ||
|
||
func GetDB() *DB { | ||
return defaultDB | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
} | ||
|
||
func InitDB(config DBConfig) { | ||
bg, cancel := context.WithTimeout(context.Background(), 5*time.Second) | ||
defer cancel() | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,8 +2,10 @@ package config | |
|
||
import ( | ||
"context" | ||
"log/slog" | ||
"os" | ||
"reflect" | ||
"sync" | ||
|
||
"github.com/naoina/toml" | ||
"github.com/sethvargo/go-envconfig" | ||
|
@@ -261,9 +263,30 @@ type Config struct { | |
|
||
func SetConfigFile(file string) { | ||
configFile = file | ||
// The config file is provided via the command line, which should be the only entry point for running | ||
// all CSGHub server commands. However, if some code accidentally calls LoadConfig in the init function | ||
// before the config file is loaded from the command line, the config system will be broken entirely. | ||
// To address this, we reset the `once` variable when SetConfigFile is called, ensuring that even if | ||
// the config is incorrect during initialization, it will be corrected when the config is loaded again | ||
// from the command line. | ||
// This is a temporary fix. We should avoid relying on a global config and instead use DI | ||
// to pass the config wherever it's needed. | ||
once = sync.OnceValues(func() (*Config, error) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
return loadConfig() | ||
}) | ||
} | ||
|
||
var once = sync.OnceValues(func() (*Config, error) { | ||
return loadConfig() | ||
}) | ||
|
||
func LoadConfig() (*Config, error) { | ||
return once() | ||
} | ||
|
||
func loadConfig() (*Config, error) { | ||
defer slog.Debug("end load config") | ||
slog.Debug("start load config") | ||
cfg := &Config{} | ||
|
||
toml.DefaultConfig.MissingField = func(typ reflect.Type, key string) error { | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,105 @@ | ||
instance_id = "bar" | ||
saas = false | ||
instance_id = "" | ||
enable_swagger = false | ||
enable_https = false | ||
api_token = "f3a7b9c1d6e5f8e2a1b5d4f9e6a2b8d7c3a4e2b1d9f6e7a8d2c5a7b4c1e3f5b8a1d4f9b7d6e2f8a5d3b1e7f9c6a8b2d1e4f7d5b6e9f2a4b3c8e1d7f995hd82hf" | ||
|
||
[api_server] | ||
port = 4321 | ||
port = 9091 | ||
public_domain = "http://localhost:9091" | ||
ssh_domain = "ssh://git@localhost:2222" | ||
|
||
[database] | ||
driver = "pg" | ||
dsn = "" | ||
timezone = "Asia/Shanghai" | ||
|
||
[redis] | ||
endpoint = "localhost:6379" | ||
max_retries = 3 | ||
min_idle_connections = 0 | ||
user = "" | ||
password = "" | ||
sentinel_mode = false | ||
sentinel_master = "" | ||
sentinel_endpoint = "" | ||
|
||
[git_server] | ||
type = "gitaly" | ||
|
||
[gitaly_server] | ||
address = "tcp://localhost:9876" | ||
storge = "default" | ||
token = "abc123secret" | ||
jwt_secret = "signing-key" | ||
|
||
[jwt] | ||
signing_key = "signing-key" | ||
valid_hour = 24 | ||
|
||
[model] | ||
deploy_timeout_in_min = 60 | ||
download_endpoint = "https://hub.opencsg.com" | ||
docker_reg_base = "opencsg-registry.cn-beijing.cr.aliyuncs.com/public/" | ||
nim_docker_secret_name = "ngc-secret" | ||
nim_ngc_secret_name = "nvidia-nim-secrets" | ||
|
||
[event] | ||
sync_interval = 1 | ||
|
||
[nats] | ||
url = "nats://natsadmin:[email protected]:4222" | ||
msg_fetch_timeout_in_sec = 5 | ||
fee_notify_no_balance_subject = "accounting.notify.nobalance" | ||
fee_request_subject = "accounting.fee.>" | ||
fee_send_subject = "accounting.fee.credit" | ||
token_send_subject = "accounting.fee.token" | ||
quota_send_subject = "accounting.fee.quota" | ||
meter_request_subject = "accounting.metering.>" | ||
meter_duration_send_subject = "accounting.metering.duration" | ||
meter_token_send_subject = "accounting.metering.token" | ||
meter_quota_send_subject = "accounting.metering.quota" | ||
order_expired_subject = "accounting.order.expired" | ||
|
||
[user] | ||
host = "http://localhost" | ||
port = 9092 | ||
signin_success_redirect_url = "http://localhost:3000/server/callback" | ||
codesouler_vscode_redirect_url = "http://127.0.0.1:37678/callback" | ||
codesouler_jetbrains_redirect_url = "http://127.0.0.1:37679/callback" | ||
|
||
[multi_sync] | ||
saasApiDomain = "" | ||
saasSyncDomain = "" | ||
|
||
[telemetry] | ||
enable = false | ||
|
||
[dataset] | ||
promptMaxJsonlFileSize = 1048576 # 1MB | ||
|
||
[workflow] | ||
endpoint = "localhost:7233" | ||
|
||
[cron_job] | ||
sync_as_client_cron_expression = "0 * * * *" | ||
calc_recom_score_cron_expression = "0 1 * * *" | ||
|
||
[dataviewer] | ||
host = "http://localhost" | ||
port = 9093 | ||
|
||
[proxy] | ||
hosts = ["opencsg.com", "sync.opencsg.com"] | ||
|
||
[casdoor] | ||
certificate = "go.mod" | ||
|
||
[s3] | ||
access_key_id = "abc" | ||
access_key_secret = "def" | ||
endpoint = "" | ||
bucket = "testcsg" | ||
enable_ssl = false | ||
url_upload_max_file_size = 5153960755 | ||
bucket_lookup = "path" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -69,21 +69,26 @@ func chProjectRoot() { | |
|
||
// Init a test db, must call `defer db.Close()` in the test | ||
func InitTestDB() *database.DB { | ||
db, _ := CreateTestDB("csghub_test") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
return db | ||
} | ||
|
||
func CreateTestDB(name string) (*database.DB, string) { | ||
ctx := context.TODO() | ||
// reuse the container, so we don't need to recreate the db for each test | ||
// https://github.com/testcontainers/testcontainers-go/issues/2726 | ||
reuse := testcontainers.CustomizeRequestOption( | ||
func(req *testcontainers.GenericContainerRequest) error { | ||
req.Reuse = true | ||
req.Name = "csghub_test" | ||
req.Name = name | ||
return nil | ||
}, | ||
) | ||
|
||
pc, err := postgres.Run(ctx, | ||
"postgres:15.7", | ||
reuse, | ||
postgres.WithDatabase("csghub_test"), | ||
postgres.WithDatabase(name), | ||
testcontainers.WithWaitStrategy( | ||
wait.ForLog("database system is ready to accept connections"). | ||
WithOccurrence(2). | ||
|
@@ -141,7 +146,7 @@ func InitTestDB() *database.DB { | |
return &database.DB{ | ||
Operator: database.Operator{Core: bdb}, | ||
BunDB: bdb, | ||
} | ||
}, dsn | ||
} | ||
|
||
// Create a random test postgres Database without txdb, | ||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cfg.MultiSync.SaasAPIDomain
should be validated to ensure it is not empty before use.