Skip to content

Commit

Permalink
Rewrite test to remove race (test_async_worker_update_pwd)
Browse files Browse the repository at this point in the history
  • Loading branch information
mafredri committed Aug 15, 2018
1 parent 4c2e413 commit da46ed5
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions async_test.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,14 @@ test_async_worker_survives_termination_of_other_worker() {

test_async_worker_update_pwd() {
local -a result
cb() { result+=("$3") }
local eval_out
cb() {
if [[ $1 == '[async/eval]' ]]; then
eval_out="$3"
else
result+=("$3")
fi
}

async_start_worker test1
t_defer async_stop_worker test1
Expand All @@ -448,10 +455,10 @@ test_async_worker_update_pwd() {
async_process_results test1 cb
done

(( $#result == 3 )) || t_error "wanted 3 results, got ${#result}"
[[ $result[2] = foobarbaz ]] || t_error "wanted async_worker_eval to output foobarbaz, got ${(q)result[2]}"
[[ -n $result[3] ]] || t_error "wanted second pwd to be non-empty"
[[ $result[1] != $result[3] ]] || t_error "wanted worker to change pwd, was ${(q)result[1]}, got ${(q)result[3]}"
(( $#result == 2 )) || t_error "wanted 2 results, got ${#result}"
[[ $eval_out = foobarbaz ]] || t_error "wanted async_worker_eval to output foobarbaz, got ${(q)eval_out}"
[[ -n $result[2] ]] || t_error "wanted second pwd to be non-empty"
[[ $result[1] != $result[2] ]] || t_error "wanted worker to change pwd, was ${(q)result[1]}, got ${(q)result[2]}"
}

setopt_helper() {
Expand Down

0 comments on commit da46ed5

Please sign in to comment.