87 lines
3.4 KiB
JavaScript
87 lines
3.4 KiB
JavaScript
// Simple test to demonstrate backend caching
|
|
const axios = require('axios');
|
|
|
|
const API_BASE = 'http://localhost:3001/api';
|
|
|
|
async function testCaching() {
|
|
console.log('🧪 Testing backend caching behavior...\n');
|
|
|
|
console.log('📊 Getting initial rate limit:');
|
|
try {
|
|
const initialRateLimit = await axios.get(`${API_BASE}/rate-limit`);
|
|
console.log(`🔄 Initial rate limit: ${initialRateLimit.data.remaining}/${initialRateLimit.data.limit} remaining\n`);
|
|
} catch (error) {
|
|
console.log(`❌ Initial rate limit error: ${error.message}\n`);
|
|
}
|
|
|
|
console.log('📊 First request - should hit GitHub API:');
|
|
const start1 = Date.now();
|
|
try {
|
|
const response1 = await axios.get(`${API_BASE}/workflow-runs`);
|
|
console.log(`✅ Response 1: ${response1.data.length} workflow runs (${Date.now() - start1}ms)`);
|
|
} catch (error) {
|
|
console.log(`❌ Error 1: ${error.message}`);
|
|
}
|
|
|
|
console.log('📊 Rate limit after first request:');
|
|
try {
|
|
const rateLimit1 = await axios.get(`${API_BASE}/rate-limit`);
|
|
console.log(`🔄 Rate limit: ${rateLimit1.data.remaining}/${rateLimit1.data.limit} remaining\n`);
|
|
} catch (error) {
|
|
console.log(`❌ Rate limit error: ${error.message}\n`);
|
|
}
|
|
|
|
console.log('📊 Second request - should hit cache:');
|
|
const start2 = Date.now();
|
|
try {
|
|
const response2 = await axios.get(`${API_BASE}/workflow-runs`);
|
|
console.log(`✅ Response 2: ${response2.data.length} workflow runs (${Date.now() - start2}ms)`);
|
|
} catch (error) {
|
|
console.log(`❌ Error 2: ${error.message}`);
|
|
}
|
|
|
|
console.log('📊 Rate limit after second request:');
|
|
try {
|
|
const rateLimit2 = await axios.get(`${API_BASE}/rate-limit`);
|
|
console.log(`🔄 Rate limit: ${rateLimit2.data.remaining}/${rateLimit2.data.limit} remaining\n`);
|
|
} catch (error) {
|
|
console.log(`❌ Rate limit error: ${error.message}\n`);
|
|
}
|
|
|
|
console.log('📊 Third request - should also hit cache:');
|
|
const start3 = Date.now();
|
|
try {
|
|
const response3 = await axios.get(`${API_BASE}/workflow-runs`);
|
|
console.log(`✅ Response 3: ${response3.data.length} workflow runs (${Date.now() - start3}ms)`);
|
|
} catch (error) {
|
|
console.log(`❌ Error 3: ${error.message}`);
|
|
}
|
|
|
|
console.log('📊 Final rate limit:');
|
|
try {
|
|
const finalRateLimit = await axios.get(`${API_BASE}/rate-limit`);
|
|
console.log(`🔄 Final rate limit: ${finalRateLimit.data.remaining}/${finalRateLimit.data.limit} remaining\n`);
|
|
} catch (error) {
|
|
console.log(`❌ Final rate limit error: ${error.message}\n`);
|
|
}
|
|
|
|
console.log('📊 Getting cache stats:');
|
|
try {
|
|
const cacheStats = await axios.get(`${API_BASE}/cache/stats`);
|
|
console.log(`💾 Cache size: ${cacheStats.data.size} entries`);
|
|
console.log(`💾 Cache keys: ${cacheStats.data.entries.slice(0, 3).join(', ')}${cacheStats.data.entries.length > 3 ? '...' : ''}\n`);
|
|
} catch (error) {
|
|
console.log(`❌ Cache stats error: ${error.message}\n`);
|
|
}
|
|
|
|
console.log('📊 Getting rate limit info:');
|
|
try {
|
|
const rateLimitInfo = await axios.get(`${API_BASE}/rate-limit`);
|
|
console.log(`🔄 Rate limit: ${rateLimitInfo.data.remaining}/${rateLimitInfo.data.limit} remaining`);
|
|
console.log(`🔄 Reset in: ${Math.round(rateLimitInfo.data.timeUntilReset / 1000)}s`);
|
|
} catch (error) {
|
|
console.log(`❌ Rate limit error: ${error.message}`);
|
|
}
|
|
}
|
|
|
|
testCaching().catch(console.error); |