1#!/bin/ksh -p
2#
3# This file and its contents are supplied under the terms of the
4# Common Development and Distribution License ("CDDL"), version 1.0.
5# You may only use this file in accordance with the terms of version
6# 1.0 of the CDDL.
7#
8# A full copy of the text of the CDDL should have accompanied this
9# source.  A copy of the CDDL is also available via the Internet at
10# http://www.illumos.org/license/CDDL.
11#
12
13#
14# Copyright (c) 2018 by Delphix. All rights reserved.
15#
16
17. $STF_SUITE/include/libtest.shlib
18. $STF_SUITE/tests/functional/cli_root/zfs_wait/zfs_wait.kshlib
19
20#
21# DESCRIPTION:
22# 'zfs wait' works when waiting for checkpoint discard to complete.
23#
24# STRATEGY:
25# 1. Create a file
26# 2. Open a file descriptor pointing to that file.
27# 3. Delete the file.
28# 4. Start a background process waiting for the delete queue to empty.
29# 5. Verify that the command doesn't return immediately.
30# 6. Close the open file descriptor.
31# 7. Verify that the command returns soon after the descriptor is closed.
32#
33
34function cleanup
35{
36	kill_if_running $pid
37	exec 3<&-
38}
39
40
41typeset -r TESTFILE="/$TESTPOOL/testfile"
42typeset pid
43
44log_onexit cleanup
45
46log_must touch $TESTFILE
47exec 3<> $TESTFILE
48log_must rm $TESTFILE
49log_bkgrnd zfs wait -t deleteq $TESTPOOL
50pid=$!
51proc_must_exist $pid
52
53exec 3<&-
54log_must sleep 0.5
55bkgrnd_proc_succeeded $pid
56
57log_pass "'zfs wait -t discard' works."
58