Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(postgres): Fix broken tests for PostgresDriver #138

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions ormconfig.gh-actions.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
[
{
"skip": false,
"skip": true,
"name": "sqlite",
"type": "sqlite",
"database": "temp/sqlite.db",
"logging": false
},
{
"skip": true,
"skip": false,
"name": "postgres",
"type": "postgres",
"host": "localhost",
Expand All @@ -18,7 +18,7 @@
"logging": false
},
{
"skip": false,
"skip": true,
"name": "mysql",
"type": "mysql",
"host": "127.0.0.1",
Expand Down
22 changes: 1 addition & 21 deletions src/driver/postgres/PostgresQueryRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import {IsolationLevel} from "../types/IsolationLevel.ts";
import {PostgresDriver} from "./PostgresDriver.ts";
import {PoolClient, QueryArrayResult} from "./typings.ts";
import {NotImplementedError} from "../../error/NotImplementedError.ts";
import {PromiseQueue} from "../../util/PromiseQueue.ts";

/**
* Runs queries on a single postgres database connection.
Expand Down Expand Up @@ -156,24 +155,6 @@ export class PostgresQueryRunner extends BaseQueryRunner implements QueryRunner
this.isTransactionActive = false;
}

private queryQueueMap = new Map<PoolClient, PromiseQueue<QueryArrayResult>>();

/**
* TODO Remove this method.
* This method is a workaround for a concurrency problem that occurs sometimes when using [email protected].
*/
private executeQuery(connection: PoolClient, query: string, parameters: any[]) {
if (!this.queryQueueMap.has(connection)) {
const queue = new PromiseQueue<QueryArrayResult>();
this.queryQueueMap.set(connection, queue);
queue.onEmpty().then(() => {
this.queryQueueMap.delete(connection);
});
}
const queue = this.queryQueueMap.get(connection);
return queue!.add(() => connection.queryArray(query, ...parameters));
}

/**
* Executes a given SQL query.
*/
Expand All @@ -191,8 +172,7 @@ export class PostgresQueryRunner extends BaseQueryRunner implements QueryRunner
let error: any | undefined;
let result: QueryArrayResult | undefined;
try {
//result = await databaseConnection.query(query, ...(parameters || []));
result = await this.executeQuery(databaseConnection, query, parameters || []);
result = await databaseConnection.queryArray(query, ...(parameters || []));
} catch (err) {
error = err;
}
Expand Down
19 changes: 6 additions & 13 deletions test/functional/schema-builder/change-column.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ import {AuroraDataApiDriver} from "../../../src/driver/aurora-data-api/AuroraDat
// import {CockroachDriver} from "../../../src/driver/cockroachdb/CockroachDriver.ts";
import {MysqlDriver} from "../../../src/driver/mysql/MysqlDriver.ts";
import {OracleDriver} from "../../../src/driver/oracle/OracleDriver.ts";
// TODO(uki00a) uncomment this when PostgresDriver is implemented.
// import {PostgresDriver} from "../../../src/driver/postgres/PostgresDriver.ts";
import {PostgresDriver} from "../../../src/driver/postgres/PostgresDriver.ts";
import {SapDriver} from "../../../src/driver/sap/SapDriver.ts";
import {AbstractSqliteDriver} from "../../../src/driver/sqlite-abstract/AbstractSqliteDriver.ts";
import {SqlServerDriver} from "../../../src/driver/sqlserver/SqlServerDriver.ts";
Expand Down Expand Up @@ -169,7 +168,7 @@ describe("schema builder > change column", () => {

const queryRunner = connection.createQueryRunner();

if (false/*connection.driver instanceof PostgresDriver*/) // TODO(uki00a) uncomment this when PostgresDriver is implemented.
if (connection.driver instanceof PostgresDriver)
await queryRunner.query(`CREATE EXTENSION IF NOT EXISTS "uuid-ossp"`);

const postMetadata = connection.getMetadata(Post);
Expand All @@ -178,9 +177,7 @@ describe("schema builder > change column", () => {
idColumn.generationStrategy = "uuid";

// depending on driver, we must change column and referenced column types
if (false/*connection.driver instanceof PostgresDriver || connection.driver instanceof CockroachDriver*/) {
// TODO(uki00a) uncomment this when PostgresDriver is implemented.
// TODO(uki00a) uncomment this when CockroachDriver is implemented.
if (connection.driver instanceof PostgresDriver/* || connection.driver instanceof CockroachDriver*/) { // TODO(uki00a) uncomment this when CockroachDriver is implemented.
idColumn.type = "uuid";
} else if (connection.driver instanceof SqlServerDriver) {
idColumn.type = "uniqueidentifier";
Expand All @@ -193,9 +190,7 @@ describe("schema builder > change column", () => {
const postTable = await queryRunner.getTable("post");
await queryRunner.release();

if (/*connection.driver instanceof PostgresDriver || */connection.driver instanceof SqlServerDriver/* || connection.driver instanceof CockroachDriver*/) {
// TODO(uki00a) uncomment this when PostgresDriver is implemented.
// TODO(uki00a) uncomment this when CockroachDriver is implemented.
if (connection.driver instanceof PostgresDriver || connection.driver instanceof SqlServerDriver/* || connection.driver instanceof CockroachDriver*/) { // TODO(uki00a) uncomment this when CockroachDriver is implemented.
postTable!.findColumnByName("id")!.isGenerated.should.be.true;
postTable!.findColumnByName("id")!.generationStrategy!.should.be.equal("uuid");

Expand Down Expand Up @@ -226,9 +221,7 @@ describe("schema builder > change column", () => {
idColumn.generationStrategy = "uuid";

// depending on driver, we must change column and referenced column types
if (false/*connection.driver instanceof PostgresDriver || connection.driver instanceof CockroachDriver*/) {
// TODO(uki00a) uncomment this when PostgresDriver is implemented.
// TODO(uki00a) uncomment this when CockroachDriver is implemented.
if (connection.driver instanceof PostgresDriver/* || connection.driver instanceof CockroachDriver*/) { // TODO(uki00a) uncomment this when CockroachDriver is implemented.
idColumn.type = "uuid";
teacherColumn.type = "uuid";
} else if (connection.driver instanceof SqlServerDriver) {
Expand All @@ -245,7 +238,7 @@ describe("schema builder > change column", () => {
const teacherTable = await queryRunner.getTable("teacher");
await queryRunner.release();

if (/*connection.driver instanceof PostgresDriver || */connection.driver instanceof SqlServerDriver) { // TODO(uki00a) uncomment this when PostgresDriver is implemented.
if (connection.driver instanceof PostgresDriver || connection.driver instanceof SqlServerDriver) {
teacherTable!.findColumnByName("id")!.isGenerated.should.be.true;
teacherTable!.findColumnByName("id")!.generationStrategy!.should.be.equal("uuid");

Expand Down
4 changes: 2 additions & 2 deletions test/github-issues/2067/issue-2067.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {runIfMain} from "../../deps/mocha.ts";
import {expect} from "../../deps/chai.ts";
import {createTestingConnections, closeTestingConnections, reloadTestingDatabases} from "../../utils/test-utils.ts";
import {Connection} from "../../../src/connection/Connection.ts";
//import {PostgresDriver} from "../../../src/driver/postgres/PostgresDriver.ts";
import {PostgresDriver} from "../../../src/driver/postgres/PostgresDriver.ts";
import {User} from "./entity/User.ts";

describe("github issues > #2067 Unhandled promise rejection warning on postgres connection issues", () => {
Expand All @@ -20,7 +20,7 @@ describe("github issues > #2067 Unhandled promise rejection warning on postgres
it("should return a catchable error on connection errors in queries", () => Promise.all(connections.map(async connection => {
const connectionFailureMessage = "Test error to simulate a connection error";

if (false/*connection.driver instanceof PostgresDriver*/) { // TODO(uki00a) uncomment this when PostgresDriver is implemented.
if (connection.driver instanceof PostgresDriver) {
connection.driver.obtainMasterConnection = () => Promise.reject<any>(new Error(connectionFailureMessage));
connection.driver.obtainSlaveConnection = () => Promise.reject<any>(new Error(connectionFailureMessage));
}
Expand Down
4 changes: 2 additions & 2 deletions test/github-issues/2128/issue-2128.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {expect} from "../../deps/chai.ts";
import { closeTestingConnections, createTestingConnections, reloadTestingDatabases } from "../../utils/test-utils.ts";
import { Connection } from "../../../src/connection/Connection.ts";
import { Post } from "./entity/Post.ts";
//import { PostgresDriver } from "../../../src/driver/postgres/PostgresDriver.ts";
import { PostgresDriver } from "../../../src/driver/postgres/PostgresDriver.ts";

describe("github issues > #2128 skip preparePersistentValue for value functions", () => {

Expand Down Expand Up @@ -38,7 +38,7 @@ describe("github issues > #2128 skip preparePersistentValue for value functions"
await connection.createQueryBuilder()
.update(Post)
.set({
meta: () => false/*connection.driver instanceof PostgresDriver*/ // TODO(uki00a) uncomment this when PostgresDriver is implemented.
meta: () => connection.driver instanceof PostgresDriver
? `'${metaAddition}'::JSONB || meta::JSONB`
: `JSON_MERGE('${metaAddition}', meta)`
})
Expand Down