Skip to content

Commit

Permalink
Add comment on locker_test.go regarding testing the session KeepAlive
Browse files Browse the repository at this point in the history
  • Loading branch information
chen-anders committed Sep 20, 2018
1 parent ca26a45 commit c25194e
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion etcd3locker/locker.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func NewWithPrefix(client *etcd3.Client, prefix string) (*etcd3Locker, error) {
}

// This method may be used if we want control over both prefix/session TTLs. This is used for testing in particular.
func NewWithLockerOptions(client *etcd3.Client, opts *LockerOptions) (*etcd3Locker, error) {
func NewWithLockerOptions(client *etcd3.Client, opts LockerOptions) (*etcd3Locker, error) {
locksMap := map[string]*etcd3Lock{}
return &etcd3Locker{Client: client, prefix: opts.Prefix(), sessionTimeout: opts.Timeout(), locks: locksMap, mutex: sync.Mutex{}}, nil
}
Expand Down
8 changes: 4 additions & 4 deletions etcd3locker/locker_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ type LockerOptions struct {
prefix string
}

func DefaultLockerOptions() *LockerOptions {
return &LockerOptions{
func DefaultLockerOptions() LockerOptions {
return LockerOptions{
timeoutSeconds: 60,
prefix: "/tusd",
}
}

func NewLockerOptions(timeout int, prefix string) *LockerOptions {
return &LockerOptions{
func NewLockerOptions(timeout int, prefix string) LockerOptions {
return LockerOptions{
timeoutSeconds: timeout,
prefix: prefix,
}
Expand Down
2 changes: 2 additions & 0 deletions etcd3locker/locker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ func TestEtcd3Locker(t *testing.T) {
a.NoError(locker.LockUpload("one"))
a.Equal(tusd.ErrFileLocked, locker.LockUpload("one"))
time.Sleep(5 * time.Second)
// test that we can't take over the upload via a different etcd3 session
// while an upload is already taking place; testing etcd3 session KeepAlive
a.Equal(tusd.ErrFileLocked, locker.LockUpload("one"))
a.NoError(locker.UnlockUpload("one"))
a.Equal(ErrLockNotHeld, locker.UnlockUpload("one"))
Expand Down

0 comments on commit c25194e

Please sign in to comment.