File size: 2,570 Bytes
af377c4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
const FIREBASE_API_KEY = 'AIzaSyCZsz4v9a9ioF5uhK2bACy8xea6iIhSZCQ';
const SERVER_URL = 'https://hari7775-resume-server.hf.space';

async function run() {
  console.log('1. Starting massive 100-job stress test to fill server queue backlog...');
  
  // Pre-generate tokens in batches of 10
  console.log('Generating 100 Firebase tokens...');
  const tokens = [];
  for (let b = 0; b < 10; b++) {
    const authBatch = Array.from({ length: 10 }).map(() =>
      fetch(`https://identitytoolkit.googleapis.com/v1/accounts:signUp?key=${FIREBASE_API_KEY}`, {
        method: 'POST',
        headers: { 'Content-Type': 'application/json' },
        body: JSON.stringify({ returnSecureToken: true })
      }).then(r => r.json()).then(d => d.idToken)
    );
    const resolved = await Promise.all(authBatch);
    tokens.push(...resolved);
  }
  console.log(`✅ ${tokens.length} tokens ready!`);

  console.log('\n🚀 Dispatching 100 heavy PDF generation requests to server...');
  const jobs = tokens.map((token, idx) => {
    const i = idx + 1;
    const html = `<!DOCTYPE html><html>
    <head>
      <link href="https://fonts.googleapis.com/css2?family=Merriweather:wght@300;400;700&display=swap" rel="stylesheet">
    </head>
    <body style="width:794px;height:1123px;padding:40px;font-family:'Merriweather',serif;">
      <h1>Massive Queue Backlog Stress Job #${i} - ${Date.now()}-${Math.random()}</h1>
      <p>Testing sustained backlog position # under 100 concurrent job load.</p>
      <div style="height:350px;background:#f3f4f6;border:2px solid #e5e7eb;border-radius:12px;margin-top:20px;"></div>
      <div style="height:350px;background:#e5e7eb;border:2px solid #d1d5db;border-radius:12px;margin-top:20px;"></div>
    </body></html>`;

    return fetch(`${SERVER_URL}/api/export-pdf`, {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json',
        'Authorization': `Bearer ${token}`
      },
      body: JSON.stringify({
        html,
        metadata: { filename: `massive_load_${i}` }
      })
    }).then(r => r.json()).then(d => {
      if (i % 10 === 0 || i <= 5) {
        console.log(`[Job #${i}/100] Server Queue Position: #${d.position} (ID: ${d.jobId?.slice(0, 8)})`);
      }
      return d;
    }).catch(e => {
      console.error(`Job #${i} error:`, e.message);
    });
  });

  console.log('\n🔥 100 requests DISPATCHED! The server queue backlog will stay active for ~1-2 minutes! Click Export PDF in your browser now!');
  await Promise.all(jobs);
  console.log('\n✅ All 100 jobs finished processing!');
}

run();