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 expectedError = new Error('test');
101cb0ef41Sopenharmony_ciconst input = { foo: 'bar' };
111cb0ef41Sopenharmony_ciconst thisArg = { baz: 'buz' };
121cb0ef41Sopenharmony_ci
131cb0ef41Sopenharmony_cifunction check(found) {
141cb0ef41Sopenharmony_ci  assert.deepStrictEqual(found, input);
151cb0ef41Sopenharmony_ci}
161cb0ef41Sopenharmony_ci
171cb0ef41Sopenharmony_ciconst handlers = {
181cb0ef41Sopenharmony_ci  start: common.mustCall(check),
191cb0ef41Sopenharmony_ci  end: common.mustCall(check),
201cb0ef41Sopenharmony_ci  asyncStart: common.mustNotCall(),
211cb0ef41Sopenharmony_ci  asyncEnd: common.mustNotCall(),
221cb0ef41Sopenharmony_ci  error: common.mustCall((found) => {
231cb0ef41Sopenharmony_ci    check(found);
241cb0ef41Sopenharmony_ci    assert.deepStrictEqual(found.error, expectedError);
251cb0ef41Sopenharmony_ci  })
261cb0ef41Sopenharmony_ci};
271cb0ef41Sopenharmony_ci
281cb0ef41Sopenharmony_cichannel.subscribe(handlers);
291cb0ef41Sopenharmony_citry {
301cb0ef41Sopenharmony_ci  channel.traceSync(function(err) {
311cb0ef41Sopenharmony_ci    assert.deepStrictEqual(this, thisArg);
321cb0ef41Sopenharmony_ci    assert.strictEqual(err, expectedError);
331cb0ef41Sopenharmony_ci    throw err;
341cb0ef41Sopenharmony_ci  }, input, thisArg, expectedError);
351cb0ef41Sopenharmony_ci
361cb0ef41Sopenharmony_ci  throw new Error('It should not reach this error');
371cb0ef41Sopenharmony_ci} catch (error) {
381cb0ef41Sopenharmony_ci  assert.deepStrictEqual(error, expectedError);
391cb0ef41Sopenharmony_ci}
40