-
Notifications
You must be signed in to change notification settings - Fork 260
Reduce lock timeout and check pid same before cleaning up #1035
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
Changes from all commits
5fe3bd9
9aba9aa
ad3f35e
8908fa9
274dfd6
6bcc09b
afa0848
315fa88
8e735b7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| package cni | ||
|
|
||
| import ( | ||
| "os" | ||
| "testing" | ||
|
|
||
| "github.com/Azure/azure-container-networking/common" | ||
| "github.com/Azure/azure-container-networking/store" | ||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| func TestMain(m *testing.M) { | ||
| // Run tests. | ||
| exitCode := m.Run() | ||
| os.Exit(exitCode) | ||
| } | ||
|
|
||
| func TestPluginSafeToRemoveLock(t *testing.T) { | ||
| tests := []struct { | ||
| name string | ||
| plugin Plugin | ||
| processName string | ||
| wantIsSafe bool | ||
| wantErr bool | ||
| }{ | ||
| { | ||
| name: "Safe to remove lock-true. Process name does not match", | ||
| plugin: Plugin{ | ||
| Plugin: &common.Plugin{ | ||
| Name: "cni", | ||
| Version: "0.3.0", | ||
| Store: store.NewMockStore("testfiles/processfound.lock"), | ||
| }, | ||
| version: "0.3.0", | ||
| }, | ||
| processName: "azure-vnet", | ||
| wantIsSafe: true, | ||
| wantErr: false, | ||
| }, | ||
| { | ||
| name: "Safe to remove lock-true. Process not running", | ||
| plugin: Plugin{ | ||
| Plugin: &common.Plugin{ | ||
| Name: "cni", | ||
| Version: "0.3.0", | ||
| Store: store.NewMockStore("testfiles/processnotfound.lock"), | ||
| }, | ||
| version: "0.3.0", | ||
| }, | ||
| processName: "azure-vnet", | ||
| wantIsSafe: true, | ||
| wantErr: false, | ||
| }, | ||
| } | ||
|
|
||
| for _, tt := range tests { | ||
| tt := tt | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| isSafe, err := tt.plugin.IsSafeToRemoveLock(tt.processName) | ||
| if tt.wantErr { | ||
| require.Error(t, err) | ||
| require.Equal(t, tt.wantIsSafe, isSafe) | ||
| } else { | ||
| require.NoError(t, err) | ||
| require.Equal(t, tt.wantIsSafe, isSafe) | ||
| } | ||
| }) | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| 1 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| -3 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,7 +25,7 @@ const ( | |
| lockExtension = ".lock" | ||
|
|
||
| // Maximum number of retries before failing a lock call. | ||
| lockMaxRetries = 200 | ||
| lockMaxRetries = 100 | ||
|
Collaborator
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. how quickly do we retry? this could go by very fast. should there be some exponential back-off, maybe?
Member
Author
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. Isn't 10 seconds long enough? 100 retries with 100ms delay
Collaborator
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. I don't know. Usually (like with http calls), we would do an exponential back-off where we wait maybe twice as long every time instead of a fixed interval (ex: 50ms, 100, 200, 400, 800, ...). But if 100x100ms is what we want, that's fine with me |
||
|
|
||
| // Delay between lock retries. | ||
| lockRetryDelay = 100 * time.Millisecond | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| package store | ||
|
|
||
| import ( | ||
| "time" | ||
| ) | ||
|
|
||
| type mockStore struct { | ||
| lockFilePath string | ||
| } | ||
|
|
||
| // NewMockStore creates a new jsonFileStore object, accessed as a KeyValueStore. | ||
| func NewMockStore(lockFilePath string) KeyValueStore { | ||
| return &mockStore{ | ||
| lockFilePath: lockFilePath, | ||
| } | ||
| } | ||
|
|
||
| // Read restores the value for the given key from persistent store. | ||
| func (ms *mockStore) Read(key string, value interface{}) error { | ||
| return nil | ||
| } | ||
|
|
||
| func (ms *mockStore) Write(key string, value interface{}) error { | ||
| return nil | ||
| } | ||
|
|
||
| func (ms *mockStore) Flush() error { | ||
| return nil | ||
| } | ||
|
|
||
| func (ms *mockStore) Lock(block bool) error { | ||
| return nil | ||
| } | ||
|
|
||
| func (ms *mockStore) Unlock(forceUnlock bool) error { | ||
| return nil | ||
| } | ||
|
|
||
| func (ms *mockStore) GetModificationTime() (time.Time, error) { | ||
| return time.Time{}, nil | ||
| } | ||
|
|
||
| func (ms *mockStore) GetLockFileModificationTime() (time.Time, error) { | ||
| return time.Time{}, nil | ||
| } | ||
|
|
||
| func (ms *mockStore) GetLockFileName() string { | ||
| return ms.lockFilePath | ||
| } | ||
|
|
||
| func (ms *mockStore) Remove() {} |
Uh oh!
There was an error while loading. Please reload this page.