fix(ci & formatting): Minor fixes: update CI workflow image and npmci package references, adjust package.json and readme URLs, and apply consistent code formatting.
This commit is contained in:
@ -3,7 +3,10 @@ import * as smartmongo from '@push.rocks/smartmongo';
|
||||
import type * as taskbuffer from '@push.rocks/taskbuffer';
|
||||
|
||||
import * as smartdata from '../ts/index.js';
|
||||
import { SmartdataDistributedCoordinator, DistributedClass } from '../ts/classes.distributedcoordinator.js'; // path might need adjusting
|
||||
import {
|
||||
SmartdataDistributedCoordinator,
|
||||
DistributedClass,
|
||||
} from '../ts/classes.distributedcoordinator.js'; // path might need adjusting
|
||||
const totalInstances = 10;
|
||||
|
||||
// =======================================
|
||||
@ -20,93 +23,100 @@ tap.test('should create a testinstance as database', async () => {
|
||||
});
|
||||
|
||||
tap.test('should instantiate DistributedClass', async (tools) => {
|
||||
const instance = new DistributedClass();
|
||||
expect(instance).toBeInstanceOf(DistributedClass);
|
||||
const instance = new DistributedClass();
|
||||
expect(instance).toBeInstanceOf(DistributedClass);
|
||||
});
|
||||
|
||||
tap.test('DistributedClass should update the time', async (tools) => {
|
||||
const distributedCoordinator = new SmartdataDistributedCoordinator(testDb);
|
||||
await distributedCoordinator.start();
|
||||
const initialTime = distributedCoordinator.ownInstance.data.lastUpdated;
|
||||
await distributedCoordinator.sendHeartbeat();
|
||||
const updatedTime = distributedCoordinator.ownInstance.data.lastUpdated;
|
||||
expect(updatedTime).toBeGreaterThan(initialTime);
|
||||
await distributedCoordinator.stop();
|
||||
const distributedCoordinator = new SmartdataDistributedCoordinator(testDb);
|
||||
await distributedCoordinator.start();
|
||||
const initialTime = distributedCoordinator.ownInstance.data.lastUpdated;
|
||||
await distributedCoordinator.sendHeartbeat();
|
||||
const updatedTime = distributedCoordinator.ownInstance.data.lastUpdated;
|
||||
expect(updatedTime).toBeGreaterThan(initialTime);
|
||||
await distributedCoordinator.stop();
|
||||
});
|
||||
|
||||
tap.test('should instantiate SmartdataDistributedCoordinator', async (tools) => {
|
||||
const distributedCoordinator = new SmartdataDistributedCoordinator(testDb);
|
||||
await distributedCoordinator.start();
|
||||
expect(distributedCoordinator).toBeInstanceOf(SmartdataDistributedCoordinator);
|
||||
await distributedCoordinator.stop();
|
||||
const distributedCoordinator = new SmartdataDistributedCoordinator(testDb);
|
||||
await distributedCoordinator.start();
|
||||
expect(distributedCoordinator).toBeInstanceOf(SmartdataDistributedCoordinator);
|
||||
await distributedCoordinator.stop();
|
||||
});
|
||||
|
||||
tap.test('SmartdataDistributedCoordinator should update leader status', async (tools) => {
|
||||
const distributedCoordinator = new SmartdataDistributedCoordinator(testDb);
|
||||
await distributedCoordinator.start();
|
||||
await distributedCoordinator.checkAndMaybeLead();
|
||||
expect(distributedCoordinator.ownInstance.data.elected).toBeOneOf([true, false]);
|
||||
await distributedCoordinator.stop();
|
||||
const distributedCoordinator = new SmartdataDistributedCoordinator(testDb);
|
||||
await distributedCoordinator.start();
|
||||
await distributedCoordinator.checkAndMaybeLead();
|
||||
expect(distributedCoordinator.ownInstance.data.elected).toBeOneOf([true, false]);
|
||||
await distributedCoordinator.stop();
|
||||
});
|
||||
|
||||
tap.test('SmartdataDistributedCoordinator should handle distributed task requests', async (tools) => {
|
||||
tap.test(
|
||||
'SmartdataDistributedCoordinator should handle distributed task requests',
|
||||
async (tools) => {
|
||||
const distributedCoordinator = new SmartdataDistributedCoordinator(testDb);
|
||||
await distributedCoordinator.start();
|
||||
|
||||
const mockTaskRequest: taskbuffer.distributedCoordination.IDistributedTaskRequest = {
|
||||
submitterId: "mockSubmitter12345", // Some unique mock submitter ID
|
||||
requestResponseId: 'uni879873462hjhfkjhsdf', // Some unique ID for the request-response
|
||||
taskName: "SampleTask",
|
||||
taskVersion: "1.0.0", // Assuming it's a version string
|
||||
taskExecutionTime: Date.now(),
|
||||
taskExecutionTimeout: 60000, // Let's say the timeout is 1 minute (60000 ms)
|
||||
taskExecutionParallel: 5, // Let's assume max 5 parallel executions
|
||||
status: 'requesting'
|
||||
submitterId: 'mockSubmitter12345', // Some unique mock submitter ID
|
||||
requestResponseId: 'uni879873462hjhfkjhsdf', // Some unique ID for the request-response
|
||||
taskName: 'SampleTask',
|
||||
taskVersion: '1.0.0', // Assuming it's a version string
|
||||
taskExecutionTime: Date.now(),
|
||||
taskExecutionTimeout: 60000, // Let's say the timeout is 1 minute (60000 ms)
|
||||
taskExecutionParallel: 5, // Let's assume max 5 parallel executions
|
||||
status: 'requesting',
|
||||
};
|
||||
|
||||
const response = await distributedCoordinator.fireDistributedTaskRequest(mockTaskRequest);
|
||||
console.log(response) // based on your expected structure for the response
|
||||
console.log(response); // based on your expected structure for the response
|
||||
await distributedCoordinator.stop();
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
tap.test('SmartdataDistributedCoordinator should update distributed task requests', async (tools) => {
|
||||
tap.test(
|
||||
'SmartdataDistributedCoordinator should update distributed task requests',
|
||||
async (tools) => {
|
||||
const distributedCoordinator = new SmartdataDistributedCoordinator(testDb);
|
||||
|
||||
|
||||
await distributedCoordinator.start();
|
||||
|
||||
const mockTaskRequest: taskbuffer.distributedCoordination.IDistributedTaskRequest = {
|
||||
submitterId: "mockSubmitter12345", // Some unique mock submitter ID
|
||||
requestResponseId: 'uni879873462hjhfkjhsdf', // Some unique ID for the request-response
|
||||
taskName: "SampleTask",
|
||||
taskVersion: "1.0.0", // Assuming it's a version string
|
||||
taskExecutionTime: Date.now(),
|
||||
taskExecutionTimeout: 60000, // Let's say the timeout is 1 minute (60000 ms)
|
||||
taskExecutionParallel: 5, // Let's assume max 5 parallel executions
|
||||
status: 'requesting'
|
||||
submitterId: 'mockSubmitter12345', // Some unique mock submitter ID
|
||||
requestResponseId: 'uni879873462hjhfkjhsdf', // Some unique ID for the request-response
|
||||
taskName: 'SampleTask',
|
||||
taskVersion: '1.0.0', // Assuming it's a version string
|
||||
taskExecutionTime: Date.now(),
|
||||
taskExecutionTimeout: 60000, // Let's say the timeout is 1 minute (60000 ms)
|
||||
taskExecutionParallel: 5, // Let's assume max 5 parallel executions
|
||||
status: 'requesting',
|
||||
};
|
||||
|
||||
|
||||
await distributedCoordinator.updateDistributedTaskRequest(mockTaskRequest);
|
||||
// Here, we can potentially check if a DB entry got updated or some other side-effect of the update method.
|
||||
await distributedCoordinator.stop();
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
tap.test('should elect only one leader amongst multiple instances', async (tools) => {
|
||||
const coordinators = Array.from({ length: totalInstances }).map(() => new SmartdataDistributedCoordinator(testDb));
|
||||
await Promise.all(coordinators.map(coordinator => coordinator.start()));
|
||||
const leaders = coordinators.filter(coordinator => coordinator.ownInstance.data.elected);
|
||||
for (const leader of leaders) {
|
||||
console.log(leader.ownInstance);
|
||||
}
|
||||
expect(leaders.length).toEqual(1);
|
||||
const coordinators = Array.from({ length: totalInstances }).map(
|
||||
() => new SmartdataDistributedCoordinator(testDb),
|
||||
);
|
||||
await Promise.all(coordinators.map((coordinator) => coordinator.start()));
|
||||
const leaders = coordinators.filter((coordinator) => coordinator.ownInstance.data.elected);
|
||||
for (const leader of leaders) {
|
||||
console.log(leader.ownInstance);
|
||||
}
|
||||
expect(leaders.length).toEqual(1);
|
||||
|
||||
// stopping clears a coordinator from being elected.
|
||||
await Promise.all(coordinators.map(coordinator => coordinator.stop()));
|
||||
// stopping clears a coordinator from being elected.
|
||||
await Promise.all(coordinators.map((coordinator) => coordinator.stop()));
|
||||
});
|
||||
|
||||
tap.test('should clean up', async () => {
|
||||
await smartmongoInstance.stopAndDumpToDir(`.nogit/dbdump/test.distributedcoordinator.ts`);
|
||||
setTimeout(() => process.exit(), 2000);
|
||||
})
|
||||
await smartmongoInstance.stopAndDumpToDir(`.nogit/dbdump/test.distributedcoordinator.ts`);
|
||||
setTimeout(() => process.exit(), 2000);
|
||||
});
|
||||
|
||||
tap.start({ throwOnError: true });
|
||||
|
@ -56,14 +56,14 @@ tap.test('should create test products with searchable fields', async () => {
|
||||
new Product('Kindle Paperwhite', 'E-reader with built-in light', 'Books', 129),
|
||||
new Product('Harry Potter', 'Fantasy book series about wizards', 'Books', 49),
|
||||
new Product('Coffee Maker', 'Automatic drip coffee machine', 'Kitchen', 89),
|
||||
new Product('Blender', 'High-speed blender for smoothies', 'Kitchen', 129)
|
||||
new Product('Blender', 'High-speed blender for smoothies', 'Kitchen', 129),
|
||||
];
|
||||
|
||||
|
||||
// Save all products to the database
|
||||
for (const product of products) {
|
||||
await product.save();
|
||||
}
|
||||
|
||||
|
||||
// Verify that we can get all products
|
||||
const allProducts = await Product.getInstances({});
|
||||
expect(allProducts.length).toEqual(products.length);
|
||||
@ -74,7 +74,7 @@ tap.test('should retrieve searchable fields for a class', async () => {
|
||||
// Use the getSearchableFields function to verify our searchable fields
|
||||
const searchableFields = getSearchableFields('Product');
|
||||
console.log('Searchable fields:', searchableFields);
|
||||
|
||||
|
||||
expect(searchableFields.length).toEqual(3);
|
||||
expect(searchableFields).toContain('name');
|
||||
expect(searchableFields).toContain('description');
|
||||
@ -85,7 +85,7 @@ tap.test('should search products by exact field match', async () => {
|
||||
// Basic field exact match search
|
||||
const electronicsProducts = await Product.getInstances({ category: 'Electronics' });
|
||||
console.log(`Found ${electronicsProducts.length} products in Electronics category`);
|
||||
|
||||
|
||||
expect(electronicsProducts.length).toEqual(4);
|
||||
});
|
||||
|
||||
@ -94,7 +94,7 @@ tap.test('should search products by basic search method', async () => {
|
||||
try {
|
||||
const iPhoneResults = await Product.search('iPhone');
|
||||
console.log(`Found ${iPhoneResults.length} products matching 'iPhone' using basic search`);
|
||||
|
||||
|
||||
expect(iPhoneResults.length).toEqual(1);
|
||||
expect(iPhoneResults[0].name).toEqual('iPhone 12');
|
||||
} catch (error) {
|
||||
@ -107,8 +107,10 @@ tap.test('should search products by basic search method', async () => {
|
||||
tap.test('should search products with searchWithLucene method', async () => {
|
||||
// Using the robust searchWithLucene method
|
||||
const wirelessResults = await Product.searchWithLucene('wireless');
|
||||
console.log(`Found ${wirelessResults.length} products matching 'wireless' using searchWithLucene`);
|
||||
|
||||
console.log(
|
||||
`Found ${wirelessResults.length} products matching 'wireless' using searchWithLucene`,
|
||||
);
|
||||
|
||||
expect(wirelessResults.length).toEqual(1);
|
||||
expect(wirelessResults[0].name).toEqual('AirPods');
|
||||
});
|
||||
@ -117,7 +119,7 @@ tap.test('should search products by category with searchWithLucene', async () =>
|
||||
// Using field-specific search with searchWithLucene
|
||||
const kitchenResults = await Product.searchWithLucene('category:Kitchen');
|
||||
console.log(`Found ${kitchenResults.length} products in Kitchen category using searchWithLucene`);
|
||||
|
||||
|
||||
expect(kitchenResults.length).toEqual(2);
|
||||
expect(kitchenResults[0].category).toEqual('Kitchen');
|
||||
expect(kitchenResults[1].category).toEqual('Kitchen');
|
||||
@ -127,7 +129,7 @@ tap.test('should search products with partial word matches', async () => {
|
||||
// Testing partial word matches
|
||||
const proResults = await Product.searchWithLucene('Pro');
|
||||
console.log(`Found ${proResults.length} products matching 'Pro'`);
|
||||
|
||||
|
||||
// Should match both "MacBook Pro" and "professionals" in description
|
||||
expect(proResults.length).toBeGreaterThan(0);
|
||||
});
|
||||
@ -136,7 +138,7 @@ tap.test('should search across multiple searchable fields', async () => {
|
||||
// Test searching across all searchable fields
|
||||
const bookResults = await Product.searchWithLucene('book');
|
||||
console.log(`Found ${bookResults.length} products matching 'book' across all fields`);
|
||||
|
||||
|
||||
// Should match "MacBook" in name and "Books" in category
|
||||
expect(bookResults.length).toBeGreaterThan(1);
|
||||
});
|
||||
@ -145,10 +147,10 @@ tap.test('should handle case insensitive searches', async () => {
|
||||
// Test case insensitivity
|
||||
const electronicsResults = await Product.searchWithLucene('electronics');
|
||||
const ElectronicsResults = await Product.searchWithLucene('Electronics');
|
||||
|
||||
|
||||
console.log(`Found ${electronicsResults.length} products matching lowercase 'electronics'`);
|
||||
console.log(`Found ${ElectronicsResults.length} products matching capitalized 'Electronics'`);
|
||||
|
||||
|
||||
// Both searches should return the same results
|
||||
expect(electronicsResults.length).toEqual(ElectronicsResults.length);
|
||||
});
|
||||
@ -161,19 +163,19 @@ tap.test('should demonstrate search fallback mechanisms', async () => {
|
||||
console.log('3. As last resort, perform in-memory filtering');
|
||||
console.log('This ensures robust search even with complex queries');
|
||||
console.log('==============================================\n');
|
||||
|
||||
|
||||
// Use a simpler term that should be found in descriptions
|
||||
// Avoid using "OR" operator which requires a text index
|
||||
const results = await Product.searchWithLucene('high');
|
||||
console.log(`Found ${results.length} products matching 'high'`);
|
||||
|
||||
|
||||
// "High-speed blender" contains "high"
|
||||
expect(results.length).toBeGreaterThan(0);
|
||||
|
||||
|
||||
// Try another fallback example that won't need $text
|
||||
const powerfulResults = await Product.searchWithLucene('powerful');
|
||||
console.log(`Found ${powerfulResults.length} products matching 'powerful'`);
|
||||
|
||||
|
||||
// "Powerful laptop for professionals" contains "powerful"
|
||||
expect(powerfulResults.length).toBeGreaterThan(0);
|
||||
});
|
||||
@ -186,7 +188,7 @@ tap.test('should explain the advantages of the integrated approach', async () =>
|
||||
console.log('4. searchWithLucene provides powerful search capabilities');
|
||||
console.log('5. Backwards compatible with existing code');
|
||||
console.log('================================================\n');
|
||||
|
||||
|
||||
expect(true).toEqual(true);
|
||||
});
|
||||
|
||||
@ -199,4 +201,4 @@ tap.test('close database connection', async () => {
|
||||
setTimeout(() => process.exit(), 2000);
|
||||
});
|
||||
|
||||
tap.start({ throwOnError: true });
|
||||
tap.start({ throwOnError: true });
|
||||
|
@ -97,7 +97,7 @@ tap.test('should save the car to the db', async (toolsArg) => {
|
||||
console.log(
|
||||
`Filled database with ${counter} of ${totalCars} Cars and memory usage ${
|
||||
process.memoryUsage().rss / 1e6
|
||||
} MB`
|
||||
} MB`,
|
||||
);
|
||||
}
|
||||
} while (counter < totalCars);
|
||||
@ -116,7 +116,7 @@ tap.test('expect to get instance of Car with shallow match', async () => {
|
||||
console.log(
|
||||
`performed ${counter} of ${totalQueryCycles} total query cycles: took ${
|
||||
Date.now() - timeStart
|
||||
}ms to query a set of 2000 with memory footprint ${process.memoryUsage().rss / 1e6} MB`
|
||||
}ms to query a set of 2000 with memory footprint ${process.memoryUsage().rss / 1e6} MB`,
|
||||
);
|
||||
}
|
||||
expect(myCars[0].deepData.sodeep).toEqual('yes');
|
||||
@ -139,7 +139,7 @@ tap.test('expect to get instance of Car with deep match', async () => {
|
||||
console.log(
|
||||
`performed ${counter} of ${totalQueryCycles} total query cycles: took ${
|
||||
Date.now() - timeStart
|
||||
}ms to deep query a set of 2000 with memory footprint ${process.memoryUsage().rss / 1e6} MB`
|
||||
}ms to deep query a set of 2000 with memory footprint ${process.memoryUsage().rss / 1e6} MB`,
|
||||
);
|
||||
}
|
||||
expect(myCars2[0].deepData.sodeep).toEqual('yes');
|
||||
@ -209,7 +209,7 @@ tap.test('should store a new Truck', async () => {
|
||||
tap.test('should return a count', async () => {
|
||||
const truckCount = await Truck.getCount();
|
||||
expect(truckCount).toEqual(1);
|
||||
})
|
||||
});
|
||||
|
||||
tap.test('should use a cursor', async () => {
|
||||
const cursor = await Car.getCursor({});
|
||||
|
Reference in New Issue
Block a user