summaryrefslogtreecommitdiffhomepage
path: root/test/rels
diff options
context:
space:
mode:
authorVladimir Kochnev <[email protected]>2016-08-03 12:09:19 +0300
committerVladimir Kochnev <[email protected]>2019-10-02 18:06:35 +0300
commit913003eaf0456e4645cad91f2622354deae10841 (patch)
tree27293f11b37df246eaf15da6a062bbfade8882bb /test/rels
parentc73b36d80f6a07862ead30a593f62b4797926110 (diff)
downloadcaxlsx-913003eaf0456e4645cad91f2622354deae10841.tar.gz
caxlsx-913003eaf0456e4645cad91f2622354deae10841.zip
Fix Relationship.instances cache.
This PR aims to fix several issues with Relationship cache: 1) It's not threadsafe, so I propose to use a TLS variable for this. 2) Memory obtained by cache remains non-freed before the next run of `serialize`. I think it should be freed immediately. 3) Memory should be freed in `ensure` block to prevent memory bloating in case of exception. *There are only two hard things in Computer Science: cache invalidation and naming things.*
Diffstat (limited to 'test/rels')
-rw-r--r--test/rels/tc_relationship.rb8
1 files changed, 8 insertions, 0 deletions
diff --git a/test/rels/tc_relationship.rb b/test/rels/tc_relationship.rb
index add1654f..845f789e 100644
--- a/test/rels/tc_relationship.rb
+++ b/test/rels/tc_relationship.rb
@@ -13,6 +13,14 @@ class TestRelationships < Test::Unit::TestCase
instance = Axlsx::Relationship.new(source_obj, Axlsx::WORKSHEET_R, 'target')
assert_equal instance.Id, Axlsx::Relationship.new(source_obj, Axlsx::WORKSHEET_R, 'target').Id
end
+
+ def test_instances_cache_is_thread_safe
+ cache1, cache2 = nil
+ t1 = Thread.new { cache1 = Axlsx::Relationship.instances }
+ t2 = Thread.new { cache2 = Axlsx::Relationship.instances }
+ [t1, t2].each(&:join)
+ assert_not_same(cache1, cache2)
+ end
def test_target_is_only_considered_for_same_attributes_check_if_target_mode_is_external
source_obj = Object.new