Skip to content

Commit

Permalink
fix tests by using git helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
M-Kusumgar committed Mar 7, 2024
1 parent b1a83c9 commit ff7a8a3
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 33 deletions.
2 changes: 1 addition & 1 deletion scripts/redis
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bash
set -e
CONTAINER_NAME=orderly.server_redis
CONTAINER_NAME=orderly.runner_redis
if [ "$1" = "start" ]; then
docker run --rm -d --name=$CONTAINER_NAME -p 127.0.0.1:6379:6379 redis
elif [ "$1" = "stop" ]; then
Expand Down
9 changes: 5 additions & 4 deletions tests/testthat/helper-orderly-runner.R
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ copy_examples <- function(examples, path_src) {
}


helper_add_git <- function(path) {
helper_add_git <- function(path, add = ".") {
gert::git_init(path)
gert::git_add(".", repo = path)
gert::git_add(add, repo = path)
user <- "author <[email protected]>"
sha <- gert::git_commit("initial", author = user, committer = user,
repo = path)
Expand Down Expand Up @@ -135,9 +135,10 @@ initialise_git_repo <- function() {
}


create_new_commit <- function(path, new_file = "new", message = "new message") {
create_new_commit <- function(path, new_file = "new", message = "new message",
add = ".") {
writeLines("new file", file.path(path, new_file))
gert::git_add(".", repo = path)
gert::git_add(add, repo = path)
user <- "author <[email protected]>"
gert::git_commit(message, author = user, committer = user, repo = path)
}
Expand Down
6 changes: 3 additions & 3 deletions tests/testthat/test-git.R
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ test_that("can get files which have been modified", {
expect_equal(git_get_modified(log$commit[[2]], repo = repo$local),
character(0))
expect_equal(git_get_modified(log$commit[[1]], repo = repo$local),
"src/parameters/orderly.R")
"src/parameters/parameters.R")
expect_equal(git_get_modified(log$commit[[1]], relative = "src/",
repo = repo$local),
"parameters/orderly.R")
"parameters/parameters.R")
expect_equal(git_get_modified(log$commit[[1]], base = log$commit[[2]],
repo = repo$local),
"src/parameters/orderly.R")
"src/parameters/parameters.R")
expect_equal(git_get_modified(log$commit[[2]], base = log$commit[[1]],
repo = repo$local),
character(0))
Expand Down
27 changes: 8 additions & 19 deletions tests/testthat/test-queue.R
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,7 @@ test_that("Can submit task", {
skip_if_no_redis()

root <- test_prepare_orderly_example("data")
gert::git_init(root)
gert::git_add(c("src", "orderly_config.yml"), repo = root)
gert::git_commit("first commit", repo = root)
helper_add_git(root, c("src", "orderly_config.yml"))

q <- new_queue_quietly(root)
worker_manager <- start_queue_workers_quietly(1, q$controller)
Expand All @@ -81,22 +79,18 @@ test_that("Can submit 2 tasks on different branches", {
skip_if_no_redis()

root <- test_prepare_orderly_example("data")
gert::git_init(root)
gert::git_add(c("src", "orderly_config.yml"), repo = root)
gert::git_commit("first commit", repo = root)
helper_add_git(root, c("src", "orderly_config.yml"))

gert::git_branch_create("branch1", repo = root)
gert::git_branch_checkout("branch1", repo = root)
write.table("test", file = file.path(root, "test.txt"))
gert::git_add("test.txt", repo = root)
gert::git_commit("branch1 commit", repo = root)
gert::git_branch_create("branch", repo = root)
gert::git_branch_checkout("branch", repo = root)
create_new_commit(root, new_file = "test.txt", add = "test.txt")

q <- new_queue_quietly(root)
worker_manager <- start_queue_workers_quietly(2, q$controller)
make_worker_dirs(root, worker_manager$id)

task_id1 <- q$submit("data", branch = "master")
task_id2 <- q$submit("data", branch = "branch1")
task_id2 <- q$submit("data", branch = "branch")
expect_worker_task_complete(task_id1, q$controller, 10)
expect_worker_task_complete(task_id2, q$controller, 10)

Expand All @@ -110,13 +104,8 @@ test_that("Can submit 2 tasks on different commit hashes", {
skip_if_no_redis()

root <- test_prepare_orderly_example("data")
gert::git_init(root)
gert::git_add(c("src", "orderly_config.yml"), repo = root)
sha1 <- gert::git_commit("first commit", repo = root)

write.table("test", file = file.path(root, "test.txt"))
gert::git_add("test.txt", repo = root)
sha2 <- gert::git_commit("second commit", repo = root)
sha1 <- helper_add_git(root, c("src", "orderly_config.yml"))$sha
sha2 <- create_new_commit(root, new_file = "test.txt", add = "test.txt")

q <- new_queue_quietly(root)
worker_manager <- start_queue_workers_quietly(2, q$controller)
Expand Down
8 changes: 2 additions & 6 deletions tests/testthat/test-runner.R
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
test_that("runner runs as expected", {
orderly_root <- test_prepare_orderly_example("data")
gert::git_init(orderly_root)
gert::git_add(c("src", "orderly_config.yml"), repo = orderly_root)
gert::git_commit("first commit", repo = orderly_root)
helper_add_git(orderly_root, c("src", "orderly_config.yml"))

worker_id <- "worker1"
make_worker_dirs(orderly_root, worker_id)
Expand All @@ -21,9 +19,7 @@ test_that("runner runs as expected", {

test_that("runner runs as expected with parameters", {
orderly_root <- test_prepare_orderly_example("parameters")
gert::git_init(orderly_root)
gert::git_add(c("src", "orderly_config.yml"), repo = orderly_root)
gert::git_commit("first commit", repo = orderly_root)
helper_add_git(orderly_root, c("src", "orderly_config.yml"))

worker_id <- "worker1"
make_worker_dirs(orderly_root, worker_id)
Expand Down

0 comments on commit ff7a8a3

Please sign in to comment.