You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

ipfs_lock_test.go 2.0 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. package lockprovider
  2. import (
  3. "testing"
  4. . "github.com/smartystreets/goconvey/convey"
  5. "gitlink.org.cn/cloudream/common/pkgs/distlock"
  6. )
  7. func Test_IPFSLock(t *testing.T) {
  8. cases := []struct {
  9. title string
  10. initLocks []distlock.Lock
  11. doLock distlock.Lock
  12. wantOK bool
  13. }{
  14. {
  15. title: "同节点,同一个Buzy锁",
  16. initLocks: []distlock.Lock{
  17. {
  18. Path: []string{IPFSLockPathPrefix, "hub1"},
  19. Name: IPFSBuzyLock,
  20. },
  21. },
  22. doLock: distlock.Lock{
  23. Path: []string{IPFSLockPathPrefix, "hub1"},
  24. Name: IPFSBuzyLock,
  25. },
  26. wantOK: true,
  27. },
  28. {
  29. title: "同节点,同一个GC锁",
  30. initLocks: []distlock.Lock{
  31. {
  32. Path: []string{IPFSLockPathPrefix, "hub1"},
  33. Name: IPFSGCLock,
  34. },
  35. },
  36. doLock: distlock.Lock{
  37. Path: []string{IPFSLockPathPrefix, "hub1"},
  38. Name: IPFSGCLock,
  39. },
  40. wantOK: true,
  41. },
  42. {
  43. title: "同时设置Buzy和GC",
  44. initLocks: []distlock.Lock{
  45. {
  46. Path: []string{IPFSLockPathPrefix, "hub1"},
  47. Name: IPFSBuzyLock,
  48. Target: *NewStringLockTarget(),
  49. },
  50. },
  51. doLock: distlock.Lock{
  52. Path: []string{IPFSLockPathPrefix, "hub1"},
  53. Name: IPFSGCLock,
  54. Target: *NewStringLockTarget(),
  55. },
  56. wantOK: false,
  57. },
  58. }
  59. for _, ca := range cases {
  60. Convey(ca.title, t, func() {
  61. ipfsLock := NewIPFSLock()
  62. for _, l := range ca.initLocks {
  63. ipfsLock.Lock("req1", l)
  64. }
  65. err := ipfsLock.CanLock(ca.doLock)
  66. if ca.wantOK {
  67. So(err, ShouldBeNil)
  68. } else {
  69. So(err, ShouldNotBeNil)
  70. }
  71. })
  72. }
  73. Convey("解锁", t, func() {
  74. ipfsLock := NewIPFSLock()
  75. lock := distlock.Lock{
  76. Path: []string{IPFSLockPathPrefix, "hub1"},
  77. Name: IPFSBuzyLock,
  78. }
  79. ipfsLock.Lock("req1", lock)
  80. err := ipfsLock.CanLock(lock)
  81. So(err, ShouldBeNil)
  82. ipfsLock.Unlock("req1", lock)
  83. lock = distlock.Lock{
  84. Path: []string{IPFSLockPathPrefix, "hub1"},
  85. Name: IPFSGCLock,
  86. }
  87. err = ipfsLock.CanLock(lock)
  88. So(err, ShouldBeNil)
  89. })
  90. }

本项目旨在将云际存储公共基础设施化,使个人及企业可低门槛使用高效的云际存储服务(安装开箱即用云际存储客户端即可,无需关注其他组件的部署),同时支持用户灵活便捷定制云际存储的功能细节。