Skip to content
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

Merged
merged 9 commits into from
Mar 6, 2023
Merged

feat: implement SyncTimeout #33

merged 9 commits into from
Mar 6, 2023

Conversation

taoky
Copy link
Member

@taoky taoky commented Mar 5, 2023

Fix #30

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"`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里用 time.Duration 是不是会更好一点,这样配置里可以写 10m, 1h 这种,可读性会好一点

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

类型改了,我看看怎么测试效果。

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

加了对配置读取和超时的测试,但是感觉新加的 test 代码挺丑的。

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

哈哈这可能跟我当初的实现有关,当时写的时候没怎么注意写方便测试的代码。

@taoky taoky changed the title feat: implement SyncTimeOut feat: implement SyncTimeout Mar 5, 2023
@taoky taoky marked this pull request as ready for review March 5, 2023 20:37
Copy link
Member

@knight42 knight42 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

dist/daemon.toml Outdated Show resolved Hide resolved
return s, nil
}

func TestWaitForSync(t *testing.T) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

_ = s.c.RemoveRepository(name)
_ = s.c.RemoveContainer(context.TODO(), prefix+name)

s.ctx = context.TODO()
Copy link
Member

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(下面两行创建的)泄漏

Copy link
Member Author

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。

pkg/server/main_test.go Outdated Show resolved Hide resolved
@taoky taoky merged commit 0ff26be into master Mar 6, 2023
@iBug iBug deleted the feature-sync-timeout branch March 6, 2023 15:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

添加同步 timeout
3 participants