Browse Source

Physics test cases, cancel previous running test properly

Allows canceling running test cases (including all tests cases) properly and without error.
PouleyKetchoupp 4 years ago
parent
commit
7f095a6092

+ 1 - 1
2d/physics_tests/test.gd

@@ -115,7 +115,7 @@ func cancel_timer():
 
 
 
 
 func is_timer_canceled():
 func is_timer_canceled():
-	return _timer.paused
+	return _timer and _timer.paused
 
 
 
 
 func wait_for_physics_ticks(tick_count):
 func wait_for_physics_ticks(tick_count):

+ 2 - 0
2d/physics_tests/tests/functional/test_character.gd

@@ -127,6 +127,8 @@ func _on_option_changed(option, checked):
 
 
 
 
 func _start_test():
 func _start_test():
+	cancel_timer()
+
 	if _moving_body:
 	if _moving_body:
 		_body_parent.remove_child(_moving_body)
 		_body_parent.remove_child(_moving_body)
 		_moving_body.queue_free()
 		_moving_body.queue_free()

+ 4 - 0
2d/physics_tests/tests/functional/test_character_pixels.gd

@@ -101,10 +101,14 @@ func _test_all():
 
 
 	# Test floor detection with no snapping.
 	# Test floor detection with no snapping.
 	yield(_start_test_case(OPTION_TEST_CASE_DETECT_FLOOR_NO_SNAP), "completed")
 	yield(_start_test_case(OPTION_TEST_CASE_DETECT_FLOOR_NO_SNAP), "completed")
+	if is_timer_canceled():
+		return
 
 
 	# Test floor detection with no snapping.
 	# Test floor detection with no snapping.
 	# In this test case, motion alternates different speeds.
 	# In this test case, motion alternates different speeds.
 	yield(_start_test_case(OPTION_TEST_CASE_DETECT_FLOOR_MOTION_CHANGES), "completed")
 	yield(_start_test_case(OPTION_TEST_CASE_DETECT_FLOOR_MOTION_CHANGES), "completed")
+	if is_timer_canceled():
+		return
 
 
 	Log.print_log("* Done.")
 	Log.print_log("* Done.")
 
 

+ 13 - 0
2d/physics_tests/tests/functional/test_character_tilemap.gd

@@ -88,12 +88,25 @@ func _test_all():
 
 
 	# RigidBody tests.
 	# RigidBody tests.
 	yield(_start_test_case(OPTION_TEST_CASE_JUMP_ONE_WAY_RIGID), "completed")
 	yield(_start_test_case(OPTION_TEST_CASE_JUMP_ONE_WAY_RIGID), "completed")
+	if is_timer_canceled():
+		return
+
 	yield(_start_test_case(OPTION_TEST_CASE_JUMP_ONE_WAY_CORNER_RIGID), "completed")
 	yield(_start_test_case(OPTION_TEST_CASE_JUMP_ONE_WAY_CORNER_RIGID), "completed")
+	if is_timer_canceled():
+		return
 
 
 	# KinematicBody tests.
 	# KinematicBody tests.
 	yield(_start_test_case(OPTION_TEST_CASE_JUMP_ONE_WAY_KINEMATIC), "completed")
 	yield(_start_test_case(OPTION_TEST_CASE_JUMP_ONE_WAY_KINEMATIC), "completed")
+	if is_timer_canceled():
+		return
+
 	yield(_start_test_case(OPTION_TEST_CASE_JUMP_ONE_WAY_CORNER_KINEMATIC), "completed")
 	yield(_start_test_case(OPTION_TEST_CASE_JUMP_ONE_WAY_CORNER_KINEMATIC), "completed")
+	if is_timer_canceled():
+		return
+
 	yield(_start_test_case(OPTION_TEST_CASE_FALL_ONE_WAY_KINEMATIC), "completed")
 	yield(_start_test_case(OPTION_TEST_CASE_FALL_ONE_WAY_KINEMATIC), "completed")
+	if is_timer_canceled():
+		return
 
 
 	Log.print_log("* Done.")
 	Log.print_log("* Done.")
 
 

+ 51 - 4
2d/physics_tests/tests/functional/test_one_way_collision.gd

@@ -44,6 +44,8 @@ var _test_step = 0
 var _test_all_angles = false
 var _test_all_angles = false
 var _lock_controls = false
 var _lock_controls = false
 
 
+var _test_canceled = false
+
 
 
 func _ready():
 func _ready():
 	if not Engine.editor_hint:
 	if not Engine.editor_hint:
@@ -225,16 +227,24 @@ func _test_all_rigid_body():
 	_set_platform_size(64.0, false)
 	_set_platform_size(64.0, false)
 	_set_rigidbody_angle(0.0, false)
 	_set_rigidbody_angle(0.0, false)
 	yield(_start_test_case(OPTION_TEST_CASE_ALL_ANGLES_RIGID), "completed")
 	yield(_start_test_case(OPTION_TEST_CASE_ALL_ANGLES_RIGID), "completed")
+	if _test_canceled:
+		return
 
 
 	_set_platform_size(64.0, false)
 	_set_platform_size(64.0, false)
 	_set_rigidbody_angle(45.0, false)
 	_set_rigidbody_angle(45.0, false)
 	yield(_start_test_case(OPTION_TEST_CASE_ALL_ANGLES_RIGID), "completed")
 	yield(_start_test_case(OPTION_TEST_CASE_ALL_ANGLES_RIGID), "completed")
+	if _test_canceled:
+		return
 
 
 	_set_platform_size(32.0, false)
 	_set_platform_size(32.0, false)
 	_set_rigidbody_angle(45.0, false)
 	_set_rigidbody_angle(45.0, false)
 	yield(_start_test_case(OPTION_TEST_CASE_ALL_ANGLES_RIGID), "completed")
 	yield(_start_test_case(OPTION_TEST_CASE_ALL_ANGLES_RIGID), "completed")
+	if _test_canceled:
+		return
 
 
 	yield(_start_test_case(OPTION_TEST_CASE_MOVING_PLATFORM_RIGID), "completed")
 	yield(_start_test_case(OPTION_TEST_CASE_MOVING_PLATFORM_RIGID), "completed")
+	if _test_canceled:
+		return
 
 
 
 
 func _test_all_kinematic_body():
 func _test_all_kinematic_body():
@@ -243,16 +253,24 @@ func _test_all_kinematic_body():
 	_set_platform_size(64.0, false)
 	_set_platform_size(64.0, false)
 	_set_rigidbody_angle(0.0, false)
 	_set_rigidbody_angle(0.0, false)
 	yield(_start_test_case(OPTION_TEST_CASE_ALL_ANGLES_KINEMATIC), "completed")
 	yield(_start_test_case(OPTION_TEST_CASE_ALL_ANGLES_KINEMATIC), "completed")
+	if _test_canceled:
+		return
 
 
 	_set_platform_size(64.0, false)
 	_set_platform_size(64.0, false)
 	_set_rigidbody_angle(45.0, false)
 	_set_rigidbody_angle(45.0, false)
 	yield(_start_test_case(OPTION_TEST_CASE_ALL_ANGLES_KINEMATIC), "completed")
 	yield(_start_test_case(OPTION_TEST_CASE_ALL_ANGLES_KINEMATIC), "completed")
+	if _test_canceled:
+		return
 
 
 	_set_platform_size(32.0, false)
 	_set_platform_size(32.0, false)
 	_set_rigidbody_angle(45.0, false)
 	_set_rigidbody_angle(45.0, false)
 	yield(_start_test_case(OPTION_TEST_CASE_ALL_ANGLES_KINEMATIC), "completed")
 	yield(_start_test_case(OPTION_TEST_CASE_ALL_ANGLES_KINEMATIC), "completed")
+	if _test_canceled:
+		return
 
 
 	yield(_start_test_case(OPTION_TEST_CASE_MOVING_PLATFORM_KINEMATIC), "completed")
 	yield(_start_test_case(OPTION_TEST_CASE_MOVING_PLATFORM_KINEMATIC), "completed")
+	if _test_canceled:
+		return
 
 
 
 
 func _test_moving_platform():
 func _test_moving_platform():
@@ -265,9 +283,13 @@ func _test_moving_platform():
 
 
 	_set_platform_angle(90.0, false)
 	_set_platform_angle(90.0, false)
 	yield(_wait_for_test(), "completed")
 	yield(_wait_for_test(), "completed")
+	if _test_canceled:
+		return
 
 
 	_set_platform_angle(-90.0, false)
 	_set_platform_angle(-90.0, false)
 	yield(_wait_for_test(), "completed")
 	yield(_wait_for_test(), "completed")
+	if _test_canceled:
+		return
 
 
 	Log.print_log("* Platform moving towards body...")
 	Log.print_log("* Platform moving towards body...")
 	_set_platform_size(64.0, false)
 	_set_platform_size(64.0, false)
@@ -276,9 +298,13 @@ func _test_moving_platform():
 
 
 	_set_platform_angle(90.0, false)
 	_set_platform_angle(90.0, false)
 	yield(_wait_for_test(), "completed")
 	yield(_wait_for_test(), "completed")
+	if _test_canceled:
+		return
 
 
 	_set_platform_angle(-90.0, false)
 	_set_platform_angle(-90.0, false)
 	yield(_wait_for_test(), "completed")
 	yield(_wait_for_test(), "completed")
+	if _test_canceled:
+		return
 
 
 	_platform_speed = 0.0
 	_platform_speed = 0.0
 	emit_signal("all_tests_done")
 	emit_signal("all_tests_done")
@@ -288,7 +314,12 @@ func _test_all():
 	Log.print_log("* TESTING ALL...")
 	Log.print_log("* TESTING ALL...")
 
 
 	yield(_test_all_rigid_body(), "completed")
 	yield(_test_all_rigid_body(), "completed")
+	if _test_canceled:
+		return
+
 	yield(_test_all_kinematic_body(), "completed")
 	yield(_test_all_kinematic_body(), "completed")
+	if _test_canceled:
+		return
 
 
 	Log.print_log("* Done.")
 	Log.print_log("* Done.")
 
 
@@ -342,7 +373,9 @@ func _start_test():
 
 
 
 
 func _reset_test(cancel_test = true):
 func _reset_test(cancel_test = true):
-	$Timer.stop()
+	_test_canceled = true
+	_on_timeout()
+	_test_canceled = false
 
 
 	_test_step = 0
 	_test_step = 0
 
 
@@ -415,13 +448,27 @@ func _should_collide():
 
 
 
 
 func _on_timeout():
 func _on_timeout():
+	cancel_timer()
+
+	if $Timer.is_stopped():
+		return
+
+	$Timer.stop()
+
+	if _test_canceled:
+		emit_signal("test_done")
+		emit_signal("all_tests_done")
+		return
+
 	if not _contact_detected and not _target_entered:
 	if not _contact_detected and not _target_entered:
 		Log.print_log("Test TIMEOUT")
 		Log.print_log("Test TIMEOUT")
 		_set_result()
 		_set_result()
 
 
-	$Timer.stop()
-
-	yield(get_tree().create_timer(0.5), "timeout")
+	yield(start_timer(0.5), "timeout")
+	if _test_canceled:
+		emit_signal("test_done")
+		emit_signal("all_tests_done")
+		return
 
 
 	var was_all_angles = _test_all_angles
 	var was_all_angles = _test_all_angles