handler_test.go 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. package lock
  2. import (
  3. "fmt"
  4. "net/url"
  5. "testing"
  6. "time"
  7. "github.com/coreos/etcd/server"
  8. "github.com/coreos/etcd/tests"
  9. "github.com/stretchr/testify/assert"
  10. )
  11. // Ensure that a lock can be acquired and released.
  12. func TestModLockAcquire(t *testing.T) {
  13. v := url.Values{}
  14. tests.RunServer(func(s *server.Server) {
  15. // Acquire lock.
  16. resp, err := tests.PutForm(fmt.Sprintf("http://%s%s", s.URL(), "/mod/lock"), v)
  17. assert.NoError(t, err)
  18. ret := tests.ReadBody(resp)
  19. assert.Equal(t, string(ret), "XXX")
  20. fmt.Println("URL:", fmt.Sprintf("http://%s%s", s.URL(), "/mod/lock"))
  21. time.Sleep(60 * time.Second)
  22. // TODO: Check that it has been acquired.
  23. // TODO: Release lock.
  24. // TODO: Check that it has been released.
  25. })
  26. }
  27. // Ensure that a lock can be acquired and another process is blocked until released.
  28. func TestModLockAcquireBlocked(t *testing.T) {
  29. // TODO: Acquire lock with process #1.
  30. // TODO: Acquire lock with process #2.
  31. // TODO: Check that process #2 has not obtained lock.
  32. // TODO: Release lock from process #1.
  33. // TODO: Check that process #2 obtains the lock.
  34. // TODO: Release lock from process #2.
  35. // TODO: Check that no lock exists.
  36. }
  37. // Ensure that an unowned lock can be released by force.
  38. func TestModLockForceRelease(t *testing.T) {
  39. // TODO: Acquire lock.
  40. // TODO: Check that it has been acquired.
  41. // TODO: Force release lock.
  42. // TODO: Check that it has been released.
  43. // TODO: Check that acquiring goroutine is notified that their lock has been released.
  44. }