11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ci
31cb0ef41Sopenharmony_ciconst common = require('../common');
41cb0ef41Sopenharmony_ci
51cb0ef41Sopenharmony_ciconst fs = require('fs');
61cb0ef41Sopenharmony_ciconst assert = require('assert');
71cb0ef41Sopenharmony_ci
81cb0ef41Sopenharmony_ciconst uncalledListener = common.mustNotCall();
91cb0ef41Sopenharmony_ciconst uncalledListener2 = common.mustNotCall();
101cb0ef41Sopenharmony_ciconst watcher = fs.watchFile(__filename, uncalledListener);
111cb0ef41Sopenharmony_ci
121cb0ef41Sopenharmony_ciwatcher.unref();
131cb0ef41Sopenharmony_ciwatcher.unref();
141cb0ef41Sopenharmony_ciwatcher.ref();
151cb0ef41Sopenharmony_ciwatcher.unref();
161cb0ef41Sopenharmony_ciwatcher.ref();
171cb0ef41Sopenharmony_ciwatcher.ref();
181cb0ef41Sopenharmony_ciwatcher.unref();
191cb0ef41Sopenharmony_ci
201cb0ef41Sopenharmony_cifs.unwatchFile(__filename, uncalledListener);
211cb0ef41Sopenharmony_ci
221cb0ef41Sopenharmony_ci// Watch the file with two different listeners.
231cb0ef41Sopenharmony_cifs.watchFile(__filename, uncalledListener);
241cb0ef41Sopenharmony_ciconst watcher2 = fs.watchFile(__filename, uncalledListener2);
251cb0ef41Sopenharmony_ci
261cb0ef41Sopenharmony_cisetTimeout(
271cb0ef41Sopenharmony_ci  common.mustCall(() => {
281cb0ef41Sopenharmony_ci    fs.unwatchFile(__filename, common.mustNotCall());
291cb0ef41Sopenharmony_ci    assert.strictEqual(watcher2.listenerCount('change'), 2);
301cb0ef41Sopenharmony_ci    fs.unwatchFile(__filename, uncalledListener);
311cb0ef41Sopenharmony_ci    assert.strictEqual(watcher2.listenerCount('change'), 1);
321cb0ef41Sopenharmony_ci    watcher2.unref();
331cb0ef41Sopenharmony_ci  }),
341cb0ef41Sopenharmony_ci  common.platformTimeout(100)
351cb0ef41Sopenharmony_ci);
36