git-lfs/lfs/gitfilter.go

29 lines
716 B
Go
Raw Normal View History

2017-10-24 17:42:00 +00:00
package lfs
import (
"github.com/git-lfs/git-lfs/v3/config"
"github.com/git-lfs/git-lfs/v3/fs"
"github.com/git-lfs/git-lfs/v3/git"
go.*,lfs: mock time in copy callback log file test In commit 00f1e9521ab5d39aab393796745189d39c27b9a0 of PR #5504 we added the TestCopyCallbackFileThrottle() test function to confirm that the CopyCallbackFile() method of GitFilter structure in the "lfs" package now throttled its output of progress messages into a log file so that, in general, no more than one message was written during the interval defined by the tasklog.DefaultLoggingThrottle value. This new throttling behaviour was added in commit 5bfa9009dafce59789b88b1a0854691b596f6e76 in the same PR. The TestCopyCallbackFileThrottle() function attempts to validate the throttling action by reading a test buffer in segments and waiting or not waiting between each read, expecting the log messages to be written or not written, as appropriate. However, because our CI test suite may experience slow execution times as a result of running in virtualized environments, reads may occur at times more than the tasklog.DefaultLoggingThrottle interval apart even without the artifical waits injected by the test function, causing the test to fail when it sees more log messages than it expects. We can avoid this problem by making the wait intervals in the test deterministic using a mocked value for the current time. We use the github.com/jmhodges/clock package for this purpose, adding an object of its Clock interface type to the GitFilter structure. In all non-test code this object is simply a wrapper for the "time" package's functions, but in our test we can use a variant which allows us to control the time values returned to the CopyCallbackFile() method, either stepping forward or not, as we desire.
2023-09-28 06:13:30 +00:00
"github.com/jmhodges/clock"
2017-10-24 17:42:00 +00:00
)
2017-10-24 19:54:09 +00:00
// GitFilter provides clean and smudge capabilities
2017-10-24 17:42:00 +00:00
type GitFilter struct {
cfg *config.Configuration
2017-10-25 17:31:15 +00:00
fs *fs.Filesystem
go.*,lfs: mock time in copy callback log file test In commit 00f1e9521ab5d39aab393796745189d39c27b9a0 of PR #5504 we added the TestCopyCallbackFileThrottle() test function to confirm that the CopyCallbackFile() method of GitFilter structure in the "lfs" package now throttled its output of progress messages into a log file so that, in general, no more than one message was written during the interval defined by the tasklog.DefaultLoggingThrottle value. This new throttling behaviour was added in commit 5bfa9009dafce59789b88b1a0854691b596f6e76 in the same PR. The TestCopyCallbackFileThrottle() function attempts to validate the throttling action by reading a test buffer in segments and waiting or not waiting between each read, expecting the log messages to be written or not written, as appropriate. However, because our CI test suite may experience slow execution times as a result of running in virtualized environments, reads may occur at times more than the tasklog.DefaultLoggingThrottle interval apart even without the artifical waits injected by the test function, causing the test to fail when it sees more log messages than it expects. We can avoid this problem by making the wait intervals in the test deterministic using a mocked value for the current time. We use the github.com/jmhodges/clock package for this purpose, adding an object of its Clock interface type to the GitFilter structure. In all non-test code this object is simply a wrapper for the "time" package's functions, but in our test we can use a variant which allows us to control the time values returned to the CopyCallbackFile() method, either stepping forward or not, as we desire.
2023-09-28 06:13:30 +00:00
clk clock.Clock
2017-10-24 17:42:00 +00:00
}
2017-10-24 19:54:09 +00:00
// NewGitFilter initializes a new *GitFilter
2017-10-24 17:42:00 +00:00
func NewGitFilter(cfg *config.Configuration) *GitFilter {
go.*,lfs: mock time in copy callback log file test In commit 00f1e9521ab5d39aab393796745189d39c27b9a0 of PR #5504 we added the TestCopyCallbackFileThrottle() test function to confirm that the CopyCallbackFile() method of GitFilter structure in the "lfs" package now throttled its output of progress messages into a log file so that, in general, no more than one message was written during the interval defined by the tasklog.DefaultLoggingThrottle value. This new throttling behaviour was added in commit 5bfa9009dafce59789b88b1a0854691b596f6e76 in the same PR. The TestCopyCallbackFileThrottle() function attempts to validate the throttling action by reading a test buffer in segments and waiting or not waiting between each read, expecting the log messages to be written or not written, as appropriate. However, because our CI test suite may experience slow execution times as a result of running in virtualized environments, reads may occur at times more than the tasklog.DefaultLoggingThrottle interval apart even without the artifical waits injected by the test function, causing the test to fail when it sees more log messages than it expects. We can avoid this problem by making the wait intervals in the test deterministic using a mocked value for the current time. We use the github.com/jmhodges/clock package for this purpose, adding an object of its Clock interface type to the GitFilter structure. In all non-test code this object is simply a wrapper for the "time" package's functions, but in our test we can use a variant which allows us to control the time values returned to the CopyCallbackFile() method, either stepping forward or not, as we desire.
2023-09-28 06:13:30 +00:00
return &GitFilter{cfg: cfg, fs: cfg.Filesystem(), clk: clock.New()}
2017-10-25 17:31:15 +00:00
}
func (f *GitFilter) ObjectPath(oid string) (string, error) {
return f.fs.ObjectPath(oid)
2017-10-24 17:42:00 +00:00
}
func (f *GitFilter) RemoteRef() *git.Ref {
return git.NewRefUpdate(f.cfg.Git, f.cfg.PushRemote(), f.cfg.CurrentRef(), nil).RemoteRef()
}