@malloydata/malloy-tests 0.0.314 → 0.0.316

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -21,14 +21,14 @@
21
21
  },
22
22
  "dependencies": {
23
23
  "@jest/globals": "^29.4.3",
24
- "@malloydata/db-bigquery": "0.0.314",
25
- "@malloydata/db-duckdb": "0.0.314",
26
- "@malloydata/db-postgres": "0.0.314",
27
- "@malloydata/db-snowflake": "0.0.314",
28
- "@malloydata/db-trino": "0.0.314",
29
- "@malloydata/malloy": "0.0.314",
30
- "@malloydata/malloy-tag": "0.0.314",
31
- "@malloydata/render": "0.0.314",
24
+ "@malloydata/db-bigquery": "0.0.316",
25
+ "@malloydata/db-duckdb": "0.0.316",
26
+ "@malloydata/db-postgres": "0.0.316",
27
+ "@malloydata/db-snowflake": "0.0.316",
28
+ "@malloydata/db-trino": "0.0.316",
29
+ "@malloydata/malloy": "0.0.316",
30
+ "@malloydata/malloy-tag": "0.0.316",
31
+ "@malloydata/render": "0.0.316",
32
32
  "events": "^3.3.0",
33
33
  "jsdom": "^22.1.0",
34
34
  "luxon": "^2.4.0",
@@ -38,5 +38,5 @@
38
38
  "@types/jsdom": "^21.1.1",
39
39
  "@types/luxon": "^2.4.0"
40
40
  },
41
- "version": "0.0.314"
41
+ "version": "0.0.316"
42
42
  }
@@ -11,15 +11,37 @@ mkdir .tmp
11
11
  SCRIPTDIR=$(cd $(dirname $0); pwd)
12
12
  DATADIR=$(dirname $SCRIPTDIR)/data/postgres
13
13
 
14
- // set these in your enviornment
15
- export PGHOST=localhost
16
- export PGPORT=5432
17
- export PGUSER=root
18
- export PGPASSWORD=postgres
14
+ # Verify required environment variables and show export commands for any that are wrong
15
+ EXPORTS=""
16
+
17
+ if [ -z "$PGHOST" ] || [ "$PGHOST" != "localhost" ]; then
18
+ EXPORTS="${EXPORTS}export PGHOST=localhost\n"
19
+ fi
20
+
21
+ if [ -z "$PGPORT" ] || [ "$PGPORT" != "5432" ]; then
22
+ EXPORTS="${EXPORTS}export PGPORT=5432\n"
23
+ fi
24
+
25
+ if [ -z "$PGUSER" ] || [ "$PGUSER" != "root" ]; then
26
+ EXPORTS="${EXPORTS}export PGUSER=root\n"
27
+ fi
28
+
29
+ if [ -z "$PGPASSWORD" ] || [ "$PGPASSWORD" != "postgres" ]; then
30
+ EXPORTS="${EXPORTS}export PGPASSWORD=postgres\n"
31
+ fi
32
+
33
+ if [ -n "$EXPORTS" ]; then
34
+ echo "Required environment variables are missing or incorrect."
35
+ echo "Run these commands in your current shell or add them to your shell startup file (~/.bashrc, ~/.zshrc, etc.):"
36
+ echo ""
37
+ echo -e "$EXPORTS"
38
+ exit 1
39
+ fi
19
40
 
20
41
  docker run -p 5432:5432 -d -v $DATADIR:/init_data \
21
42
  --name postgres-malloy \
22
43
  -e POSTGRES_USER=root -e POSTGRES_PASSWORD=postgres \
44
+ -e TZ=UTC \
23
45
  --health-cmd pg_isready \
24
46
  --health-interval 10s \
25
47
  --health-timeout 5s \
@@ -36,6 +58,9 @@ done
36
58
 
37
59
  echo "Container $CONTAINER_NAME is now healthy!"
38
60
 
61
+ echo "Loading data ..."
39
62
  # configure
40
63
  echo CREATE EXTENSION tsm_system_rows\; | psql
41
64
  gunzip -c ${DATADIR}/malloytest-postgres.sql.gz | psql
65
+
66
+ echo "Ready"
@@ -51,3 +51,7 @@ describe('misc tests for regressions that have no better home', () => {
51
51
  }
52
52
  });
53
53
  });
54
+
55
+ afterAll(async () => {
56
+ await runtime.connection.close();
57
+ });
@@ -121,3 +121,7 @@ describe('emits events', () => {
121
121
  });
122
122
  });
123
123
  });
124
+
125
+ afterAll(async () => {
126
+ await runtime.connection.close();
127
+ });
@@ -74,10 +74,7 @@ describe('experimental dialects', () => {
74
74
  }
75
75
  }
76
76
 
77
- const connection = new DuckdbXConnection(
78
- duckdbX,
79
- 'test/data/duckdb/duckdb_test.db'
80
- );
77
+ const connection = new DuckdbXConnection(duckdbX, ':memory:');
81
78
 
82
79
  class DuckdbXDialect extends DuckDBDialect {
83
80
  experimental = true;
@@ -45,3 +45,7 @@ describe('turducken', () => {
45
45
  expect(qsql).toContain(`FROM (${sql}) as base`);
46
46
  });
47
47
  });
48
+
49
+ afterAll(async () => {
50
+ await runtime.connection.close();
51
+ });
@@ -348,3 +348,7 @@ describe('tags in results', () => {
348
348
  expect(tags.has('n4')).toBeTruthy();
349
349
  });
350
350
  });
351
+
352
+ afterAll(async () => {
353
+ await runtime.connection.close();
354
+ });
@@ -0,0 +1,24 @@
1
+ import {RuntimeList, allDatabases} from '../../runtimes';
2
+ import {databasesFromEnvironmentOr} from '../../util';
3
+ import '../../util/db-jest-matchers';
4
+
5
+ const runtimes = new RuntimeList(databasesFromEnvironmentOr(allDatabases));
6
+
7
+ describe.each(runtimes.runtimeList)(
8
+ 'connection close test %s',
9
+ (conName, runtime) => {
10
+ const n = runtime.dialect.sqlMaybeQuoteIdentifier('n');
11
+ test.each(Array.from({length: 50}, (_, i) => i + 1))(
12
+ 'run SELECT %i',
13
+ async queryNum => {
14
+ await expect(`
15
+ run: ${conName}.sql("""SELECT ${queryNum} as ${n} """)
16
+ `).malloyResultMatches(runtime, {n: queryNum});
17
+ }
18
+ );
19
+ }
20
+ );
21
+
22
+ afterAll(async () => {
23
+ await runtimes.closeAll();
24
+ });
@@ -713,6 +713,22 @@ describe.each(runtimes.runtimeList)('%s: query tz', (dbName, runtime) => {
713
713
  ).malloyResultMatches(runtime, {mex_day: mex_19.toJSDate()});
714
714
  });
715
715
 
716
+ test.when(
717
+ !brokenIn('trino', dbName) && !brokenIn('presto', dbName) /* mtoy */
718
+ )('truncate week', async () => {
719
+ // the 19th in mexico is a wednesday, so trunc to the 15th
720
+ const mex_19 = LuxonDateTime.fromISO('2020-02-19T00:00:00', {zone});
721
+ // Find the sunday before then
722
+ const mex_sunday = mex_19.minus({days: mex_19.weekday % 7});
723
+ await expect(
724
+ `run: ${dbName}.sql("SELECT 1 as x") -> {
725
+ timezone: '${zone}'
726
+ extend: { dimension: utc_midnight is @2020-02-20 00:00:00[UTC] }
727
+ select: mex_week is utc_midnight.week
728
+ }`
729
+ ).malloyResultMatches(runtime, {mex_week: mex_sunday.toJSDate()});
730
+ });
731
+
716
732
  test.when(
717
733
  !brokenIn('trino', dbName) && !brokenIn('presto', dbName) /* mtoy */
718
734
  )('cast timestamp to date', async () => {
@@ -766,3 +766,7 @@ describe('unsupported type tests', () => {
766
766
  expect(result.data.value[0]['geo']).toBeDefined();
767
767
  });
768
768
  });
769
+
770
+ afterAll(async () => {
771
+ await runtimeList.closeAll();
772
+ });
@@ -102,3 +102,7 @@ describe.each(runtimes.runtimeList)('%s', (databaseName, runtime) => {
102
102
  expect(model3._modelDef.contents['a']).not.toBeDefined();
103
103
  });
104
104
  });
105
+
106
+ afterAll(async () => {
107
+ await runtimes.closeAll();
108
+ });
package/src/runtimes.ts CHANGED
@@ -132,6 +132,17 @@ export class DuckDBTestConnection extends DuckDBConnection {
132
132
  }
133
133
  }
134
134
 
135
+ export class DuckDBROTestConnection extends DuckDBTestConnection {
136
+ constructor(name: string, databasePath?: string, workingDirectory?: string) {
137
+ super({
138
+ name,
139
+ databasePath,
140
+ workingDirectory,
141
+ readOnly: true,
142
+ });
143
+ }
144
+ }
145
+
135
146
  export class DuckDBWASMTestConnection extends DuckDBWASMConnection {
136
147
  // we probably need a better way to do this.
137
148
 
@@ -190,6 +201,12 @@ export function runtimeFor(dbName: string): SingleConnectionRuntime {
190
201
  connection = new PostgresTestConnection(dbName);
191
202
  break;
192
203
  case 'duckdb':
204
+ connection = new DuckDBROTestConnection(
205
+ dbName,
206
+ 'test/data/duckdb/duckdb_test.db'
207
+ );
208
+ break;
209
+ case 'duckdb_rw':
193
210
  connection = new DuckDBTestConnection(
194
211
  dbName,
195
212
  'test/data/duckdb/duckdb_test.db'
@@ -298,8 +315,8 @@ export class RuntimeList {
298
315
  for (const [_key, runtime] of this.runtimeMap) {
299
316
  await runtime.connection.close();
300
317
  }
301
- // Unfortunate hack to avoid slow to die background threads tripping
302
- // up jest
303
- await new Promise(resolve => setTimeout(resolve, 10000));
318
+ // TODO delete this line if it turns out not to be needed.
319
+ // At one time duckdb_wasm needed this
320
+ // await new Promise(resolve => setTimeout(resolve, 2000));
304
321
  }
305
322
  }