fix(test): fix test case for table deletion and optimize code

This commit is contained in:
Philipp Kunz 2024-06-23 13:33:53 +02:00
parent 367bacb954
commit 84c355c499
5 changed files with 42 additions and 17 deletions

24
changelog.md Normal file
View File

@ -0,0 +1,24 @@
# Changelog
## {{nextVersion}} - {{nextVersionMessage}}
### Changed
- Updated description
- Updated tsconfig
- Updated npmextra.json: githost
- Switched to new org scheme
## 2.0.0 - BREAKING CHANGE(core): switch to esm
### Changed
- Switched to ECMAScript modules
## 1.0.9 - fix(TTL): tables now have a default TTL for data of 1 MONTH
### Fixed
- Tables now have a default TTL (Time-To-Live) for data of 1 month
## 1.0.10 - fix(TimDataTable): cleanup
### Fixed
- Cleaned up TimDataTable configuration

View File

@ -1,4 +1,4 @@
Copyright (c) 2022 Lossless GmbH (hello@lossless.com)
Copyright (c) 2022 Task Venture Capital GmbH (hello@task.vc)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal

View File

@ -72,16 +72,6 @@ tap.test('should delete old entries', async (toolsArg) => {
await toolsArg.delayFor(5000);
});
tap.test('should delete the table', async () => {
await table.delete();
// Verify table deletion
const result = await testClickhouseDb.clickhouseHttpClient.queryPromise(`
SHOW TABLES FROM ${testClickhouseDb.options.database} LIKE '${table.options.tableName}'
`);
console.log('Table exists after deletion:', result);
expect(result.length).toEqual(0);
});
tap.test('should stream new entries', async (toolsArg) => {
const stream = table.watchNewEntries();
const subscription = stream.subscribe((entry) => {
@ -101,4 +91,14 @@ tap.test('should stream new entries', async (toolsArg) => {
subscription.unsubscribe();
});
tap.test('should delete the table', async () => {
await table.delete();
// Verify table deletion
const result = await testClickhouseDb.clickhouseHttpClient.queryPromise(`
SHOW TABLES FROM ${testClickhouseDb.options.database} LIKE '${table.options.tableName}'
`);
console.log('Table exists after deletion:', result);
expect(result.length).toEqual(0);
});
export default tap.start();

View File

@ -1,8 +1,8 @@
/**
* autocreated commitinfo by @pushrocks/commitinfo
* autocreated commitinfo by @push.rocks/commitinfo
*/
export const commitinfo = {
name: '@push.rocks/smartclickhouse',
version: '2.0.17',
version: '2.0.18',
description: 'A TypeScript-based ODM for ClickHouse databases that supports creating, managing, and querying tables with a focus on handling time-series data.'
}

View File

@ -270,6 +270,7 @@ export class TimeDataTable {
return new plugins.smartrx.rxjs.Observable((observer) => {
const pollInterval = 1000; // Poll every 1 second
let lastTimestamp: number;
let intervalId: NodeJS.Timeout;
const fetchLastEntryTimestamp = async () => {
const lastEntry = await this.smartClickHouseDbRef.clickhouseHttpClient.queryPromise(`
@ -292,13 +293,13 @@ export class TimeDataTable {
const startPolling = async () => {
await fetchLastEntryTimestamp();
const intervalId = setInterval(fetchNewEntries, pollInterval);
// Cleanup on unsubscribe
return () => clearInterval(intervalId);
intervalId = setInterval(fetchNewEntries, pollInterval);
};
startPolling().catch((err) => observer.error(err));
// Cleanup on unsubscribe
return () => clearInterval(intervalId);
});
}
}