-
Notifications
You must be signed in to change notification settings - Fork 228
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Eliminate box indirection in resources. Fixes #40. * Add tests for resource cleanup.
- Loading branch information
1 parent
613f966
commit f23e729
Showing
6 changed files
with
81 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,36 @@ | ||
defmodule RustlerTest.ResourceTest do | ||
use ExUnit.Case, async: true | ||
use Bitwise | ||
|
||
test "resource creation and interaction" do | ||
resource = RustlerTest.resource_make | ||
resource = RustlerTest.resource_make() | ||
assert resource == "" # A resource looks like an empty binary :( | ||
assert RustlerTest.resource_get_integer_field(resource) == 0 | ||
RustlerTest.resource_set_integer_field(resource, 10) | ||
assert RustlerTest.resource_get_integer_field(resource) == 10 | ||
end | ||
|
||
test "resource cleanup" do | ||
# Create a bunch of unreferenced resources for the GC to cleanup. | ||
for i <- 0..1000 do | ||
resource = RustlerTest.resource_make() | ||
RustlerTest.resource_set_integer_field(resource, i) | ||
end | ||
|
||
# Clean them up. Don't crash. | ||
:erlang.garbage_collect() | ||
end | ||
|
||
test "resource cleanup 2" do | ||
# Create a bunch of unreferenced resources for the GC to cleanup. | ||
for i <- 0..1000 do | ||
RustlerTest.resource_make_immutable((i * 0x11235813) &&& 0xffffffff) | ||
end | ||
|
||
# Clean them up. Don't crash. | ||
:erlang.garbage_collect() | ||
|
||
# Erlang's exact GC should have cleaned all that up. | ||
assert RustlerTest.resource_immutable_count() == 0 | ||
end | ||
end |