-
Notifications
You must be signed in to change notification settings - Fork 11
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
feat: implement SyncTimeout #33
Conversation
pkg/server/config.go
Outdated
LogLevel string `mapstructure:"log_level,omitempty" validate:"omitempty,eq=debug|eq=info|eq=warn|eq=error"` | ||
ListenAddr string `mapstructure:"listen_addr,omitempty" validate:"omitempty,hostport"` | ||
BindIP string `mapstructure:"bind_ip,omitempty" validate:"omitempty,ip"` | ||
NamePrefix string `mapstructure:"name_prefix,omitempty" validate:"-"` | ||
PostSync []string `mapstructure:"post_sync,omitempty" validate:"-"` | ||
ImagesUpgradeInterval string `mapstructure:"images_upgrade_interval,omitempty" validate:"omitempty,cron"` | ||
SyncTimeOut int `mapstructure:"sync_timeout,omitempty" validate:"omitempty,gte=0"` |
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.
这里用 time.Duration
是不是会更好一点,这样配置里可以写 10m
, 1h
这种,可读性会好一点
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.
类型改了,我看看怎么测试效果。
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.
加了对配置读取和超时的测试,但是感觉新加的 test 代码挺丑的。
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.
哈哈这可能跟我当初的实现有关,当时写的时候没怎么注意写方便测试的代码。
e32fb01
to
fff846f
Compare
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.
LGTM!
return s, nil | ||
} | ||
|
||
func TestWaitForSync(t *testing.T) { |
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.
👍
pkg/server/main_test.go
Outdated
_ = s.c.RemoveRepository(name) | ||
_ = s.c.RemoveContainer(context.TODO(), prefix+name) | ||
|
||
s.ctx = context.TODO() |
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.
这里我建议让调用方(具体的 test)传入 context,test 跑完后就能 cancel context,尽量避免 goroutine(下面两行创建的)泄漏
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.
这里改成了 testcase 开头根据 context.Background()
建一个带 cancel 的 context,然后后面都用这个 ctx。
Fix #30