-
Notifications
You must be signed in to change notification settings - Fork 321
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve snapshotting cleanup in parallel tests (#1800)
We cannot forward all work of the snapshot reporter to the main process, because `expect_snapshot_helper()` uses the return value of the `take_snapshot()` method. So this must be called in the subprocess. This is also good for performance, because the snapshot comparison code still runs in the subprocess, and we don't copy potentially large objects between processes. The disadvantage is that we need slightly more complicated reporters, both in the subprocess and in the main process, to make sure that both processes are doing the right type of snapshot cleanup. Closes #1797. Simplifies and improves #1788 and #1793.
- Loading branch information
1 parent
3ac8a78
commit 496f827
Showing
14 changed files
with
271 additions
and
45 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
|
||
MainprocessSnapshotReporter <- R6::R6Class("MainprocessSnapshotReporter", | ||
inherit = SnapshotReporter, | ||
public = list( | ||
end_file = function() { | ||
# No thing to do, this is done in the subprocess | ||
} | ||
) | ||
) | ||
|
||
SubprocessSnapshotReporter <- R6::R6Class("SubprocessSnapshotReporter", | ||
inherit = SnapshotReporter, | ||
public = list( | ||
start_file = function(path, test = NULL) { | ||
private$filename <- path | ||
private$test <- test | ||
super$start_file(path, test) | ||
}, | ||
|
||
end_file = function() { | ||
private$filename <- NULL | ||
super$end_file() | ||
}, | ||
|
||
end_context = function(context) { | ||
private$context <- NULL | ||
super$end_context() | ||
}, | ||
|
||
end_test = function(context, test) { | ||
private$context <- NULL | ||
private$test <- NULL | ||
super$end_test(context, test) | ||
}, | ||
|
||
start_test = function(context, test) { | ||
private$context <- context | ||
private$test <- test | ||
super$start_test(context, test) | ||
}, | ||
|
||
announce_file_snapshot = function(name) { | ||
private$event("announce_file_snapshot", name) | ||
super$announce_file_snapshot(name) | ||
}, | ||
|
||
end_reporter = function() { | ||
# do not delete unused snapshots, that's up to the main process | ||
} | ||
), | ||
private = list( | ||
filename = NULL, | ||
context = NULL, | ||
test = NULL, | ||
event = function(cmd, ...) { | ||
msg <- list( | ||
code = PROCESS_MSG, | ||
type = "snapshotter", | ||
cmd = cmd, | ||
filename = private$filename, | ||
context = context, | ||
test = test, | ||
time = NULL, | ||
args = list(...) | ||
) | ||
class(msg) <- c("testthat_message", "callr_message", "condition") | ||
signalCondition(msg) | ||
} | ||
) | ||
) |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Oops, something went wrong.