Skip to content

Commit c6dec4e

Browse files
authored
fix(test): Fix Serial-related tests for temp table (#18)
1 parent d68ead0 commit c6dec4e

File tree

7 files changed

+83
-84
lines changed

7 files changed

+83
-84
lines changed

packages/gaussdb-cursor/test/transactions.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,12 @@ const assert = require('assert')
22
const Cursor = require('../')
33
const gaussdb = require('gaussdb-node')
44

5-
// SKIP: 不支持 LISTEN/NOFITY statement
6-
// https://github.com/HuaweiCloudDeveloper/gaussdb-drivers/blob/master-dev/diff-gaussdb-postgres.md#%E4%B8%8D%E6%94%AF%E6%8C%81-listennofity-statement
7-
describe.skip('transactions', () => {
5+
describe('transactions', () => {
86
it('can execute multiple statements in a transaction', async () => {
97
const client = new gaussdb.Client()
108
await client.connect()
119
await client.query('begin')
12-
await client.query('CREATE TEMP TABLE foobar(id SERIAL PRIMARY KEY)')
10+
await client.query('CREATE TEMP TABLE foobar(id INTEGER PRIMARY KEY)')
1311
const cursor = client.query(new Cursor('SELECT * FROM foobar'))
1412
const rows = await new Promise((resolve, reject) => {
1513
cursor.read(10, (err, rows) => (err ? reject(err) : resolve(rows)))
@@ -23,7 +21,7 @@ describe.skip('transactions', () => {
2321
const client = new gaussdb.Client()
2422
await client.connect()
2523
await client.query('begin')
26-
await client.query('CREATE TEMP TABLE foobar(id SERIAL PRIMARY KEY)')
24+
await client.query('CREATE TEMP TABLE foobar(id INTEGER PRIMARY KEY)')
2725
const cursor = client.query(new Cursor('SELECT * FROM foobar'))
2826
await new Promise((resolve) => cursor.close(resolve))
2927
await client.query('ALTER TABLE foobar ADD COLUMN name TEXT')
@@ -35,7 +33,7 @@ describe.skip('transactions', () => {
3533
await client.connect()
3634
await client.query('begin')
3735
// create a cursor that has no data response
38-
const createText = 'CREATE TEMP TABLE foobar(id SERIAL PRIMARY KEY)'
36+
const createText = 'CREATE TEMP TABLE foobar(id INTEGER PRIMARY KEY)'
3937
const cursor = client.query(new Cursor(createText))
4038
const err = await new Promise((resolve) => cursor.read(100, resolve))
4139
assert.ifError(err)
Lines changed: 53 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,57 @@
11
'use strict'
2-
// const helper = require('./test-helper')
3-
// const assert = require('assert')
4-
5-
// SKIP: 不支持 临时表Serial
6-
// https://github.com/HuaweiCloudDeveloper/gaussdb-drivers/blob/master-dev/diff-gaussdb-postgres.md#%E4%B8%8D%E6%94%AF%E6%8C%81-%E4%B8%B4%E6%97%B6%E8%A1%A8serial
7-
8-
/*
9-
const pool = new helper.gaussdb.Pool()
10-
pool.connect(
11-
assert.success(function (client, done) {
12-
helper.versionGTE(
13-
client,
14-
90200,
15-
assert.success(function (jsonSupported) {
16-
if (!jsonSupported) {
17-
console.log('skip json test on older versions of postgres')
18-
done()
19-
return pool.end()
2+
const helper = require('./test-helper')
3+
const suite = new helper.Suite()
4+
const assert = require('assert')
5+
6+
suite.test('json type parsing', function (done) {
7+
const client = helper.client()
8+
9+
// Check if JSON is supported
10+
client.query('SHOW server_version_num', function (err, versionResult) {
11+
if (err) {
12+
done(err)
13+
return
14+
}
15+
16+
const versionNum = parseInt(versionResult.rows[0].server_version_num)
17+
if (versionNum < 90200) {
18+
console.log('skip json test on older versions of postgres')
19+
client.end()
20+
done()
21+
return
22+
}
23+
24+
client.query('CREATE TEMP TABLE stuff(id INTEGER PRIMARY KEY, data JSON)', function (err) {
25+
if (err) {
26+
done(err)
27+
return
28+
}
29+
30+
const value = { name: 'Brian', age: 250, alive: true, now: new Date() }
31+
client.query('INSERT INTO stuff (id, data) VALUES (1, $1)', [value], function (err) {
32+
if (err) {
33+
done(err)
34+
return
2035
}
21-
client.query('CREATE TEMP TABLE stuff(id SERIAL PRIMARY KEY, data JSON)')
22-
const value = { name: 'Brian', age: 250, alive: true, now: new Date() }
23-
client.query('INSERT INTO stuff (data) VALUES ($1)', [value])
24-
client.query(
25-
'SELECT * FROM stuff',
26-
assert.success(function (result) {
27-
assert.equal(result.rows.length, 1)
28-
assert.equal(typeof result.rows[0].data, 'object')
29-
const row = result.rows[0].data
30-
assert.strictEqual(row.name, value.name)
31-
assert.strictEqual(row.age, value.age)
32-
assert.strictEqual(row.alive, value.alive)
33-
assert.equal(JSON.stringify(row.now), JSON.stringify(value.now))
34-
done()
35-
pool.end()
36-
})
37-
)
36+
37+
client.query('SELECT * FROM stuff', function (err, result) {
38+
if (err) {
39+
done(err)
40+
return
41+
}
42+
43+
assert.equal(result.rows.length, 1)
44+
assert.equal(typeof result.rows[0].data, 'object')
45+
const row = result.rows[0].data
46+
assert.strictEqual(row.name, value.name)
47+
assert.strictEqual(row.age, value.age)
48+
assert.strictEqual(row.alive, value.alive)
49+
assert.equal(JSON.stringify(row.now), JSON.stringify(value.now))
50+
51+
client.end()
52+
done()
53+
})
3854
})
39-
)
55+
})
4056
})
41-
)
42-
*/
57+
})

packages/gaussdb-node/test/integration/client/no-data-tests.js

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,20 @@
11
'use strict'
2-
// const helper = require('./test-helper')
3-
// const suite = new helper.Suite()
4-
// const assert = require('assert')
2+
const helper = require('./test-helper')
3+
const suite = new helper.Suite()
4+
const assert = require('assert')
55

6-
// SKIP: 不支持 临时表Serial
7-
// https://github.com/HuaweiCloudDeveloper/gaussdb-drivers/blob/master-dev/diff-gaussdb-postgres.md#%E4%B8%8D%E6%94%AF%E6%8C%81-%E4%B8%B4%E6%97%B6%E8%A1%A8serial
8-
9-
/*
106
suite.test('noData message handling', function () {
117
const client = helper.client()
128

139
client.query({
1410
name: 'boom',
15-
text: 'create temp table boom(id serial, size integer)',
11+
text: 'create temp table boom(id integer primary key, size integer)',
1612
})
1713

1814
client.query(
1915
{
2016
name: 'insert',
21-
text: 'insert into boom(size) values($1)',
17+
text: 'insert into boom(id, size) values(1, $1)',
2218
values: [100],
2319
},
2420
function (err, result) {
@@ -30,7 +26,8 @@ suite.test('noData message handling', function () {
3026
)
3127

3228
client.query({
33-
name: 'insert',
29+
name: 'insert-2',
30+
text: 'insert into boom(id, size) values(2, $1)',
3431
values: [101],
3532
})
3633

@@ -48,4 +45,3 @@ suite.test('noData message handling', function () {
4845

4946
client.on('drain', client.end.bind(client))
5047
})
51-
*/

packages/gaussdb-node/test/integration/client/parse-int-8-tests.js

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,17 @@
11
'use strict'
22

3-
// const helper = require('../test-helper')
4-
// const gaussdb = helper.gaussdb
5-
// const suite = new helper.Suite()
6-
// const assert = require('assert')
3+
const helper = require('../test-helper')
4+
const gaussdb = helper.gaussdb
5+
const suite = new helper.Suite()
6+
const assert = require('assert')
77

8-
// SKIP: 不支持 临时表Serial
9-
// https://github.com/HuaweiCloudDeveloper/gaussdb-drivers/blob/master-dev/diff-gaussdb-postgres.md#%E4%B8%8D%E6%94%AF%E6%8C%81-%E4%B8%B4%E6%97%B6%E8%A1%A8serial
10-
11-
/*
128
const pool = new gaussdb.Pool(helper.config)
139
suite.test('ability to turn on and off parser', function () {
1410
if (helper.args.binary) return false
1511
pool.connect(
1612
assert.success(function (client, done) {
1713
gaussdb.defaults.parseInt8 = true
18-
client.query('CREATE TEMP TABLE asdf(id SERIAL PRIMARY KEY)')
14+
client.query('CREATE TEMP TABLE asdf(id INTEGER PRIMARY KEY)')
1915
client.query(
2016
'SELECT COUNT(*) as "count", \'{1,2,3}\'::bigint[] as array FROM asdf',
2117
assert.success(function (res) {
@@ -40,4 +36,3 @@ suite.test('ability to turn on and off parser', function () {
4036
})
4137
)
4238
})
43-
*/

packages/gaussdb-node/test/integration/client/simple-query-tests.js

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,12 @@ test('prepared statements do not mutate params', function () {
6767
})
6868
})
6969

70-
// SKIP: 不支持 临时表Serial
71-
// https://github.com/HuaweiCloudDeveloper/gaussdb-drivers/blob/master-dev/diff-gaussdb-postgres.md#%E4%B8%8D%E6%94%AF%E6%8C%81-%E4%B8%B4%E6%97%B6%E8%A1%A8serial
72-
73-
/*
7470
test('multiple simple queries', function () {
7571
const client = helper.client()
76-
client.query({ text: "create temp table bang(id serial, name varchar(5));insert into bang(name) VALUES('boom');" })
77-
client.query("insert into bang(name) VALUES ('yes');")
72+
client.query({
73+
text: "create temp table bang(id integer, name varchar(5));insert into bang(id, name) VALUES(1, 'boom');",
74+
})
75+
client.query("insert into bang(id, name) VALUES (2, 'yes');")
7876
const query = client.query(new Query('select name from bang'))
7977
assert.emits(query, 'row', function (row) {
8078
assert.equal(row['name'], 'boom')
@@ -84,7 +82,6 @@ test('multiple simple queries', function () {
8482
})
8583
client.on('drain', client.end.bind(client))
8684
})
87-
*/
8885

8986
test('multiple select statements', function () {
9087
const client = helper.client()
Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,21 @@
1-
// const helper = require('../test-helper')
2-
// const suite = new helper.Suite()
1+
const helper = require('../test-helper')
2+
const suite = new helper.Suite()
33

4-
// SKIP: 不支持 临时表Serial
5-
// https://github.com/HuaweiCloudDeveloper/gaussdb-drivers/blob/master-dev/diff-gaussdb-postgres.md#%E4%B8%8D%E6%94%AF%E6%8C%81-%E4%B8%B4%E6%97%B6%E8%A1%A8serial
6-
7-
/*
84
suite.testAsync('timeout causing query crashes', async () => {
95
const client = new helper.Client()
106
await client.connect()
11-
await client.query('CREATE TEMP TABLE foobar( name TEXT NOT NULL, id SERIAL)')
7+
await client.query('CREATE TEMP TABLE foobar( name TEXT NOT NULL, id INTEGER PRIMARY KEY)')
128
await client.query('BEGIN')
139
await client.query("SET LOCAL statement_timeout TO '1ms'")
1410
let count = 0
11+
let idCounter = 1
1512
while (count++ < 5000) {
1613
try {
17-
await client.query('INSERT INTO foobar(name) VALUES ($1)', [Math.random() * 1000 + ''])
14+
await client.query('INSERT INTO foobar(id, name) VALUES ($1, $2)', [idCounter++, Math.random() * 1000 + ''])
1815
} catch (e) {
1916
await client.query('ROLLBACK')
17+
break
2018
}
2119
}
2220
await client.end()
2321
})
24-
*/

packages/gaussdb-query-stream/test/error.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ helper('error', function (client) {
2323
})
2424
})
2525

26-
// SKIP: 不支持 LISTEN/NOFITY statement
27-
// https://github.com/HuaweiCloudDeveloper/gaussdb-drivers/blob/master-dev/diff-gaussdb-postgres.md#%E4%B8%8D%E6%94%AF%E6%8C%81-listennofity-statement
2826
describe('error recovery', () => {
2927
// created from https://github.com/chrisdickinson/pg-test-case
3028
it('recovers from a streaming error in a transaction', async () => {
@@ -35,7 +33,10 @@ describe('error recovery', () => {
3533
updated timestamp
3634
)`)
3735
await client.query(`BEGIN;`)
38-
const query = new QueryStream(`INSERT INTO frobnicators (id, updated) VALUES ($1, $2) RETURNING "id"`, [1, Date.now()])
36+
const query = new QueryStream(`INSERT INTO frobnicators (id, updated) VALUES ($1, $2) RETURNING "id"`, [
37+
1,
38+
Date.now(),
39+
])
3940
let error: Error | undefined = undefined
4041
query.on('data', console.log).on('error', (e) => {
4142
error = e

0 commit comments

Comments
 (0)