Skip to content

Commit

Permalink
Fixed memory leaks in concurrent tests
Browse files Browse the repository at this point in the history
  • Loading branch information
marcusnaslund committed May 10, 2016
1 parent c2aff3f commit 82c3379
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 14 deletions.
2 changes: 1 addition & 1 deletion test/concurrent/PromiseCollectorTest.ooc
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ PromiseCollectorTest: class extends Fixture {
promises += Promise start(func { for (i in 0 .. 10_000_000) { } })
promises += Promise start(func { for (i in 0 .. 10_000_000) { } })
expect(promises wait())
promises clear()
promises clear() . free()
})
this add("wait with timeout", func {
promises := PromiseCollector new()
Expand Down
2 changes: 1 addition & 1 deletion test/concurrent/PromiseTest.ooc
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ PromiseTest: class extends Fixture {
expect(promise2 wait(), is true)
result := future wait(t"cancel")
expect(result == t"cancel")
(result, promise, future) free()
(result, promise, promise2, future) free()
})
this add("nonblocking free", func {
promise2 := Promise start(this counter)
Expand Down
17 changes: 7 additions & 10 deletions test/concurrent/RecycleBinTest.ooc
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@ use concurrent
MyClass: class {
content: Int
bin: static RecycleBin<This>
freed: static VectorList<This>
allocated: static Int = 0
freed: static Int = 0
init: func (=content) { This allocated += 1 }
free: override func {
// < 0 means force free
if (this content < 0)
freed add(this)
if (this content < 0) {
This freed += 1
super()
}
else
this bin add(this)
}
Expand All @@ -36,22 +38,17 @@ RecycleBinTest: class extends Fixture {
allocationCount := 2 * binSize
bin := RecycleBin<MyClass> new(binSize, func (instance: MyClass) { instance content = -1; instance free() })
MyClass bin = bin
freed := VectorList<MyClass> new()
MyClass freed = freed

for (i in 0 .. allocationCount)
MyClass create(i) free()
expect(bin isFull)
expect(freed count, is equal to(allocationCount - binSize))
for (i in 0 .. freed count)
expect(freed[i] content, is equal to(-1))
expect(MyClass freed, is equal to(binSize))

for (i in 0 .. bin _list count)
expect(bin _list[i] content, is greaterOrEqual than(0))

bin free()
expect(freed count, is equal to(MyClass allocated))
freed free()
expect(MyClass freed, is equal to(MyClass allocated))
})
}
}
Expand Down
5 changes: 3 additions & 2 deletions test/concurrent/SynchronizedQueueTest.ooc
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,15 @@ SynchronizedQueueTest: class extends Fixture {
this add("multiple threads", This _testMultipleThreads)
this add("multiple threads (class)", This _testMultipleThreadsWithClass)
this add("clear and empty", func {
queue := SynchronizedQueue<Cell<ULong>> new()
queue := SynchronizedQueue<Int> new()
for (i in 0 .. 10) {
queue enqueue(Cell<ULong> new(i))
queue enqueue(i)
expect(queue count, is equal to(i + 1))
}
expect(queue empty, is false)
queue clear()
expect(queue empty, is true)
queue free()
})
}
_testMultipleThreads: static func {
Expand Down
1 change: 1 addition & 0 deletions test/concurrent/ThreadPoolTest.ooc
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ ThreadPoolTest: class extends Fixture {
comparison := t"fail"
result := future wait(comparison)
expect(result == comparison)
pool free()
})
this add("wait with timeout", func {
pool := ThreadPool new(2)
Expand Down
2 changes: 2 additions & 0 deletions test/concurrent/ThreadTest.ooc
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ ThreadTest: class extends Fixture {
otherId free()
(job as Closure) free()
expect(myId equals(Thread currentThreadId()), is true)
thisThreadInstance free()
otherThreadInstance free()
}
_timedJoin: static func {
job := func {
Expand Down
4 changes: 4 additions & 0 deletions test/concurrent/WaitLockTest.ooc
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ WaitLockTest: class extends Fixture {
expect(waitResult, is true)
waitingThread cancel()
expect(waitingThread wait(1.0), is true)
(testThread _code as Closure) free()
(waitingThread _code as Closure) free()
(testThread, waitingThread, waitLock, globalMutex) free()
}
_testWakeWithPassingCondition: static func {
Expand Down Expand Up @@ -108,6 +110,8 @@ WaitLockTest: class extends Fixture {
waitingThread start()
expect(testThread wait(1.0), is true)
expect(waitingThread alive(), is false)
(testThread _code as Closure) free()
(waitingThread _code as Closure) free()
(testThread, waitingThread, waitLock) free()
}
}
Expand Down

0 comments on commit 82c3379

Please sign in to comment.