11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ci
31cb0ef41Sopenharmony_ciconst common = require('../common');
41cb0ef41Sopenharmony_ciconst dc = require('diagnostics_channel');
51cb0ef41Sopenharmony_ciconst assert = require('assert');
61cb0ef41Sopenharmony_ci
71cb0ef41Sopenharmony_ciconst channel = dc.tracingChannel('test');
81cb0ef41Sopenharmony_ci
91cb0ef41Sopenharmony_ciconst expectedResult = { foo: 'bar' };
101cb0ef41Sopenharmony_ciconst input = { foo: 'bar' };
111cb0ef41Sopenharmony_ciconst thisArg = { baz: 'buz' };
121cb0ef41Sopenharmony_ciconst arg = { baz: 'buz' };
131cb0ef41Sopenharmony_ci
141cb0ef41Sopenharmony_cifunction check(found) {
151cb0ef41Sopenharmony_ci  assert.strictEqual(found, input);
161cb0ef41Sopenharmony_ci}
171cb0ef41Sopenharmony_ci
181cb0ef41Sopenharmony_ciconst handlers = {
191cb0ef41Sopenharmony_ci  start: common.mustCall(check),
201cb0ef41Sopenharmony_ci  end: common.mustCall((found) => {
211cb0ef41Sopenharmony_ci    check(found);
221cb0ef41Sopenharmony_ci    assert.strictEqual(found.result, expectedResult);
231cb0ef41Sopenharmony_ci  }),
241cb0ef41Sopenharmony_ci  asyncStart: common.mustNotCall(),
251cb0ef41Sopenharmony_ci  asyncEnd: common.mustNotCall(),
261cb0ef41Sopenharmony_ci  error: common.mustNotCall()
271cb0ef41Sopenharmony_ci};
281cb0ef41Sopenharmony_ci
291cb0ef41Sopenharmony_ciassert.strictEqual(channel.start.hasSubscribers, false);
301cb0ef41Sopenharmony_cichannel.subscribe(handlers);
311cb0ef41Sopenharmony_ciassert.strictEqual(channel.start.hasSubscribers, true);
321cb0ef41Sopenharmony_ciconst result1 = channel.traceSync(function(arg1) {
331cb0ef41Sopenharmony_ci  assert.strictEqual(arg1, arg);
341cb0ef41Sopenharmony_ci  assert.strictEqual(this, thisArg);
351cb0ef41Sopenharmony_ci  return expectedResult;
361cb0ef41Sopenharmony_ci}, input, thisArg, arg);
371cb0ef41Sopenharmony_ciassert.strictEqual(result1, expectedResult);
381cb0ef41Sopenharmony_ci
391cb0ef41Sopenharmony_cichannel.unsubscribe(handlers);
401cb0ef41Sopenharmony_ciassert.strictEqual(channel.start.hasSubscribers, false);
411cb0ef41Sopenharmony_ciconst result2 = channel.traceSync(function(arg1) {
421cb0ef41Sopenharmony_ci  assert.strictEqual(arg1, arg);
431cb0ef41Sopenharmony_ci  assert.strictEqual(this, thisArg);
441cb0ef41Sopenharmony_ci  return expectedResult;
451cb0ef41Sopenharmony_ci}, input, thisArg, arg);
461cb0ef41Sopenharmony_ciassert.strictEqual(result2, expectedResult);
47