Skip to content

Commit 686c7f6

Browse files
authored
Merge pull request #85 from ThePrez:fix/autocloseandtracetests
fixup failing testcases on main
2 parents 8da05ef + 2af1b99 commit 686c7f6

File tree

4 files changed

+27
-47
lines changed

4 files changed

+27
-47
lines changed

src/connection/query.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,10 @@ export class Query<T> {
3434
return (undefined === id || '' === id) ? undefined : Query.globalQueryList.find(query => query.correlationId === id);
3535
}
3636

37-
public static getOpenIds(forJob?: string) {
37+
public static getOpenIds(forJob?: SQLJob) {
3838
return this.globalQueryList
39-
.filter(q => q.job.id === forJob || forJob === undefined)
39+
.filter(q => q.job == forJob || forJob === undefined)
40+
.filter(q => q.getState() === QueryState.NOT_YET_RUN || q.getState() === QueryState.RUN_MORE_DATA_AVAILABLE )
4041
.map(q => q.correlationId);
4142
}
4243

@@ -67,13 +68,13 @@ export class Query<T> {
6768
let queryObject;
6869
if (this.isCLCommand) {
6970
queryObject = {
70-
id: SQLJob.getNewUniqueRequestId(`clcommand`),
71+
id: SQLJob.getNewUniqueId(`clcommand`),
7172
type: `cl`,
7273
cmd: this.sql
7374
};
7475
} else {
7576
queryObject = {
76-
id: SQLJob.getNewUniqueRequestId(`query`),
77+
id: SQLJob.getNewUniqueId(`query`),
7778
type: this.isPrepared ? `prepare_sql_execute` : `sql`,
7879
sql: this.sql,
7980
rows: rowsToFetch,
@@ -103,7 +104,7 @@ export class Query<T> {
103104
throw new Error('Statement has already been fully run');
104105
}
105106
let queryObject = {
106-
id: SQLJob.getNewUniqueRequestId(`fetchMore`),
107+
id: SQLJob.getNewUniqueId(`fetchMore`),
107108
cont_id: this.correlationId,
108109
type: `sqlmore`,
109110
sql: this.sql,
@@ -127,12 +128,14 @@ export class Query<T> {
127128
if (this.correlationId && this.state !== QueryState.RUN_DONE) {
128129
this.state = QueryState.RUN_DONE;
129130
let queryObject = {
130-
id: SQLJob.getNewUniqueRequestId(`sqlclose`),
131+
id: SQLJob.getNewUniqueId(`sqlclose`),
131132
cont_id: this.correlationId,
132133
type: `sqlclose`,
133134
};
134135

135136
return this.job.send(JSON.stringify(queryObject));
137+
} else if(undefined === this.correlationId) {
138+
this.state = QueryState.RUN_DONE;
136139
}
137140
}
138141

src/connection/sqlJob.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,14 @@ export class SQLJob {
3838
private traceFile: string|undefined;
3939
private isTracingChannelData: boolean = false;
4040

41+
//currently unused but we will inevitably need a unique ID assigned to each instance
42+
// since server job names can be reused in some circumstances
43+
private uniqueId = SQLJob.getNewUniqueId(`sqljob`);
44+
4145
id: string | undefined;
4246

4347

44-
public static getNewUniqueRequestId(prefix: string = `sqljob`): string {
48+
public static getNewUniqueId(prefix: string = `id`): string {
4549
return prefix + (++SQLJob.uniqueIdCounter);
4650
}
4751

@@ -108,7 +112,7 @@ export class SQLJob {
108112
.join(`;`)
109113

110114
const connectionObject = {
111-
id: SQLJob.getNewUniqueRequestId(),
115+
id: SQLJob.getNewUniqueId(),
112116
type: `connect`,
113117
props: props.length > 0 ? props : undefined
114118
}
@@ -141,7 +145,7 @@ export class SQLJob {
141145

142146
async getVersion(): Promise<VersionCheckResult> {
143147
const verObj = {
144-
id: SQLJob.getNewUniqueRequestId(),
148+
id: SQLJob.getNewUniqueId(),
145149
type: `getversion`
146150
};
147151

@@ -162,7 +166,7 @@ export class SQLJob {
162166

163167
async getTraceData(): Promise<GetTraceDataResult> {
164168
const tracedataReqObj = {
165-
id: SQLJob.getNewUniqueRequestId(),
169+
id: SQLJob.getNewUniqueId(),
166170
type: `gettracedata`
167171
};
168172

@@ -179,7 +183,7 @@ export class SQLJob {
179183

180184
async setTraceConfig(dest: ServerTraceDest, level: ServerTraceLevel): Promise<SetConfigResult> {
181185
const reqObj = {
182-
id: SQLJob.getNewUniqueRequestId(),
186+
id: SQLJob.getNewUniqueId(),
183187
type: `setconfig`,
184188
tracedest: dest,
185189
tracelevel: level
@@ -230,9 +234,13 @@ export class SQLJob {
230234
return this.query<JobLogEntry>(query).run();
231235
}
232236

237+
getUniqueId() {
238+
return this.uniqueId;
239+
}
240+
233241
async close() {
234242
const exitObject = {
235-
id: SQLJob.getNewUniqueRequestId(),
243+
id: SQLJob.getNewUniqueId(),
236244
type: `exit`
237245
};
238246

src/testing/jobs.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ export const JobsSuite: TestSuite = {
5555
let newJob = new SQLJob();
5656
await newJob.connect();
5757
let trace = await newJob.getTraceData();
58-
assert.equal(``, trace.tracedata);
58+
assert.notEqual(undefined, trace.tracedata);
5959
newJob.close();
6060
}},
6161

@@ -92,20 +92,19 @@ export const JobsSuite: TestSuite = {
9292
const noAutoClose = newJob.query(`select * from QIWS.QCUSTCDT`, {autoClose: false});
9393
const neverRuns = newJob.query(`select * from QIWS.QCUSTCDT`, {autoClose: true});
9494

95-
assert.strictEqual(Query.getOpenIds(newJob.id).length, 3);
95+
assert.strictEqual(Query.getOpenIds(newJob).length, 3);
9696

9797
// If we ran this, two both autoClose statements would be cleaned up
9898
// await Query.cleanup();
9999

100100
await Promise.all([autoCloseAnyway.run(1), noAutoClose.run(1)]);
101-
102-
assert.strictEqual(Query.getOpenIds(newJob.id).length, 3);
101+
assert.strictEqual(Query.getOpenIds(newJob).length, 3);
103102

104103
// Now cleanup should auto close autoCloseAnyway and neverRuns,
105104
// but not noAutoClose because it hasn't finished running
106105
await Query.cleanup();
107106

108-
const leftOverIds = Query.getOpenIds(newJob.id);
107+
const leftOverIds = Query.getOpenIds(newJob);
109108
assert.strictEqual(leftOverIds.length, 1);
110109

111110
assert.strictEqual(noAutoClose.getId(), leftOverIds[0]);

src/testing/manager.ts

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -66,36 +66,6 @@ export const ManagerSuite: TestSuite = {
6666
assert.strictEqual(JobManager.selectedJob, -1);
6767
}},
6868

69-
{name: `runSQL method`, test: async () => {
70-
assert.strictEqual(ServerComponent.isInstalled(), true);
71-
72-
// Ensure we have a blank manager first
73-
await JobManager.endAll();
74-
assert.strictEqual(JobManager.getRunningJobs().length, 0);
75-
assert.strictEqual(JobManager.selectedJob, -1);
76-
77-
const query = `select * from qiws.qcustcdt`;
78-
79-
// Run query with no jobs should still work, using the standard API
80-
const rowsA = await JobManager.runSQL(query);
81-
assert.notStrictEqual(rowsA.length, 0);
82-
83-
await JobManager.newJob();
84-
85-
// Check the job exists
86-
assert.strictEqual(JobManager.getRunningJobs().length, 1);
87-
assert.strictEqual(JobManager.selectedJob, 0);
88-
89-
// Run query will run the statement using the selected job
90-
const rowsB = await JobManager.runSQL(query);
91-
assert.notStrictEqual(rowsB.length, 0);
92-
93-
// End the jobs
94-
await JobManager.endAll();
95-
assert.strictEqual(JobManager.getRunningJobs().length, 0);
96-
assert.strictEqual(JobManager.selectedJob, -1);
97-
}},
98-
9969
{name: `Set selected by name`, test: async () => {
10070
assert.strictEqual(ServerComponent.isInstalled(), true);
10171

0 commit comments

Comments
 (0)