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

70 lines
1.5 KiB

  1. /*
  2. *
  3. * Copyright 2018 gRPC authors.
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. *
  17. */
  18. package grpcsync
  19. import "testing"
  20. func TestEventHasFired(t *testing.T) {
  21. e := NewEvent()
  22. if e.HasFired() {
  23. t.Fatal("e.HasFired() = true; want false")
  24. }
  25. if !e.Fire() {
  26. t.Fatal("e.Fire() = false; want true")
  27. }
  28. if !e.HasFired() {
  29. t.Fatal("e.HasFired() = false; want true")
  30. }
  31. }
  32. func TestEventDoneChannel(t *testing.T) {
  33. e := NewEvent()
  34. select {
  35. case <-e.Done():
  36. t.Fatal("e.HasFired() = true; want false")
  37. default:
  38. }
  39. if !e.Fire() {
  40. t.Fatal("e.Fire() = false; want true")
  41. }
  42. select {
  43. case <-e.Done():
  44. default:
  45. t.Fatal("e.HasFired() = false; want true")
  46. }
  47. }
  48. func TestEventMultipleFires(t *testing.T) {
  49. e := NewEvent()
  50. if e.HasFired() {
  51. t.Fatal("e.HasFired() = true; want false")
  52. }
  53. if !e.Fire() {
  54. t.Fatal("e.Fire() = false; want true")
  55. }
  56. for i := 0; i < 3; i++ {
  57. if !e.HasFired() {
  58. t.Fatal("e.HasFired() = false; want true")
  59. }
  60. if e.Fire() {
  61. t.Fatal("e.Fire() = true; want false")
  62. }
  63. }
  64. }