-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
Copy pathtraceCalls.js
157 lines (135 loc) · 5.02 KB
/
traceCalls.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
/* Copyright (c) 2024, Oracle and/or its affiliates. */
/******************************************************************************
*
* This software is dual-licensed to you under the Universal Permissive License
* (UPL) 1.0 as shown at https://oss.oracle.com/licenses/upl and Apache License
* 2.0 as shown at https://www.apache.org/licenses/LICENSE-2.0. You may choose
* either license.
*
* If you elect to accept the software under the Apache License, Version 2.0,
* the following applies:
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* NAME
* 307. traceCalls.js
*
* DESCRIPTION
* Testing traces.
*
*****************************************************************************/
'use strict';
const oracledb = require('oracledb');
const assert = require('assert');
const dbConfig = require('./dbconfig.js');
describe('307. traceCalls.js', function() {
let conn;
let roundTripSpans = 4; // pre-23ai
after(async () => {
// restore to default tracing.
oracledb.traceHandler.setTraceInstance();
if (conn) {
await conn.close();
}
});
before(async () => {
conn = await oracledb.getConnection(dbConfig);
if (!oracledb.thin) {
roundTripSpans = 0; // onBeginRoundTrip, onBeginRoundTrip are not called.
} else if (conn.oracleServerVersion >= 2304002405) {
roundTripSpans = 2;
}
});
describe('307.1 test the default traceHandler interface behaviour', () => {
let conn;
const traceHandler = oracledb.traceHandler;
let traceInstance;
let logs = [];
const userContext = {k1: 'val1'};
class myTraceHandler extends traceHandler.TraceHandlerBase {
constructor(config) {
super(config);
}
onBeginRoundTrip(traceContext) {
logs.push(traceContext);
return userContext;
}
onEndRoundTrip(traceContext, userContext) {
logs.push({...traceContext, ...userContext});
}
onEnterFn(traceContext) {
logs.push(traceContext);
return userContext;
}
onExitFn(traceContext, userContext) {
logs.push({...traceContext, ...userContext});
}
}
beforeEach(() => {
logs = [];
conn = undefined;
traceInstance = new myTraceHandler({enable: true});
});
afterEach(async () => {
// release the custom instance.
oracledb.traceHandler.setTraceInstance();
if (conn) {
await conn.close();
}
});
it('307.1.1 getConnection default behaviour with no instance set', async function() {
conn = await oracledb.getConnection(dbConfig);
assert((logs.length === 0));
});
it('307.1.2 getConnection behaviour with a custom instance enabling trace', async function() {
traceInstance.enable();
oracledb.traceHandler.setTraceInstance(traceInstance);
conn = await oracledb.getConnection(dbConfig);
// getConnection causes onEnterFn, onExitFn to be called for
// public API getConnection. onBeginRoundTrip, onEndRoundTrip callbacks are called
// for each roundtrip to DB.
assert((logs.length === (roundTripSpans * 2 + 2)));
}); // 307.1.4
it('307.1.3 getConnection behaviour with a custom instance disabling trace', async function() {
traceInstance.disable();
oracledb.traceHandler.setTraceInstance(traceInstance);
conn = await oracledb.getConnection(dbConfig);
// getConnection causes onEnterFn, onExitFn to be called for
// public API getConnection. onBeginRoundTrip, onEndRoundTrip callbacks are called
// for each roundtrip to DB.
assert((logs.length === 0));
}); // 307.1.4
it('307.1.4 test getConnection fail behaviour with custom instance enabling trace ', async function() {
traceInstance.enable();
oracledb.traceHandler.setTraceInstance(traceInstance);
const wrongConfig = Object.assign({}, dbConfig);
wrongConfig.password = 'nil';
await assert.rejects(
async () => await oracledb.getConnection(wrongConfig),
/ORA-01017:/
);
assert((logs.length === (roundTripSpans * 2 + 2)));
}); // 307.1.4
it('307.1.5 test getConnection fail behaviour with custom instance disabling trace ', async function() {
traceInstance.disable();
oracledb.traceHandler.setTraceInstance(traceInstance);
const wrongConfig = Object.assign({}, dbConfig);
wrongConfig.password = 'nil';
await assert.rejects(
async () => await oracledb.getConnection(wrongConfig),
/ORA-01017:/
);
assert((logs.length === 0));
}); // 307.1.5
}); // 307.1
});