summaryrefslogtreecommitdiff
path: root/utilities
diff options
context:
space:
mode:
Diffstat (limited to 'utilities')
-rw-r--r--utilities/utilities.go2
-rw-r--r--utilities/utilities_test.go39
2 files changed, 40 insertions, 1 deletions
diff --git a/utilities/utilities.go b/utilities/utilities.go
index 76acbd2..7b96bef 100644
--- a/utilities/utilities.go
+++ b/utilities/utilities.go
@@ -76,7 +76,7 @@ func SeekForAppend(file *os.File) (err error) {
return
}
-var GenerateConnectionId func() uint64 = func() func() uint64 {
+var GenerateUniqueId func() uint64 = func() func() uint64 {
var nextConnectionId uint64 = 0
return func() uint64 {
return atomic.AddUint64(&nextConnectionId, 1)
diff --git a/utilities/utilities_test.go b/utilities/utilities_test.go
new file mode 100644
index 0000000..72a11fb
--- /dev/null
+++ b/utilities/utilities_test.go
@@ -0,0 +1,39 @@
+package utilities
+
+import (
+ "sync"
+ "testing"
+ "time"
+)
+
+func TestReadAfterCloseOnBufferedChannel(t *testing.T) {
+ communication := make(chan int, 100)
+
+ maxC := 0
+
+ wg := sync.WaitGroup{}
+ wg.Add(2)
+
+ go func() {
+ counter := 0
+ for range make([]int, 50) {
+ communication <- counter
+ counter++
+ }
+ close(communication)
+ wg.Done()
+ }()
+
+ go func() {
+ time.Sleep(2 * time.Second)
+ for c := range communication {
+ maxC = c
+ }
+ wg.Done()
+ }()
+
+ wg.Wait()
+ if maxC != 49 {
+ t.Fatalf("Did not read all sent items from a buffered channel after channel.")
+ }
+}