@@ -20,31 +20,49 @@ def test_build_finalise():
2020
2121
2222def test_build_finalise_multiple_instances_same_index ():
23- pytest .skip ("TODO: turn back on" )
2423 inst = ErrorV .from_build_args (code = 2 , message = "Hello world" )
2524
25+ original_instance_index = inst .instance_index
26+
2627 assert inst .code == 2
2728 assert inst .message == "Hello world"
2829
29- inst_same_ptr = ErrorV (inst .instance_ptr )
30+ inst_same_index = ErrorV (inst .instance_index )
3031
31- assert inst_same_ptr .code == 2
32- assert inst_same_ptr .message == "Hello world"
32+ assert inst_same_index .code == 2
33+ assert inst_same_index .message == "Hello world"
3334 assert inst .initialised
34- assert inst .is_associated
3535
3636 inst .finalise ()
37- inst_same_ptr .finalise ()
37+ # # Currently this causes a hard stop.
38+ # # That's the right behaviour.
39+ # # We will make it not be a hard fail when we switch to result types.
40+ # inst_same_index.finalise()
3841 assert not inst .initialised
39- assert not inst .is_associated
40-
41- # Fun mess you can get yourself into if you use the same pointer
42- # and it is finalised elsewhere
43- assert inst_same_ptr .code != 2
44- # This is true as the Python has no way of knowing
45- # that it has been finalised elsewhere
46- # (you basically need rust's borrow checker to not stuff this up)
47- assert inst_same_ptr .initialised
48- # This is how you can check for actual association
49- # (given this, maybe want to change how `initialised` works)
50- assert not inst_same_ptr .is_associated
42+
43+ ### Problem 1 ###
44+ # # With the current implementation,
45+ # # finalising via `inst` does not cause `inst_same_index` to also be finalised
46+ # assert not inst_same_index.initialised
47+
48+ inst_new = ErrorV .from_build_args (code = 3 , message = "Didn't expect this" )
49+ # New instance uses the newly freed index.
50+ assert inst_new .instance_index == original_instance_index
51+ # Which means the new instance and the instance
52+ # which was initialised previously now have the same instance index
53+ assert inst_new .instance_index == inst_same_index .instance_index
54+
55+ ### Problem 2 ###
56+ # So, if we look at `inst_same_index`'s attribute values, we get a surprise
57+ # The code isn't 2 as was set above.
58+ # Instead, the value has changed 'in the background' i.e. our view is 'stale'.
59+ assert inst_same_index .code == 3
60+ assert inst_same_index .message == "Didn't expect this"
61+
62+ # Something like this is what we actually want to happen
63+ # (if we try to access via inst_same_index again,
64+ # we get told that our view is out of date).
65+ # Could be warning or error, not sure what makes more sense...
66+ with pytest .raises (StaleViewError ):
67+ inst_same_index .code
68+ inst_same_index .message
0 commit comments