Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions scripts/continuous-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/bash

# Continuous test script that runs send-test-request.sh with 1 request in a loop
# Usage: ./scripts/continuous-test.sh
# Press Ctrl+C to stop

echo "Starting continuous test loop - sending 1 request at a time"
echo "Press Ctrl+C to stop"
echo ""

# Counter for tracking total requests
counter=1

# Trap SIGINT (Ctrl+C) to exit gracefully and show total
trap 'echo ""; echo "Stopping continuous test..."; echo "Total requests sent: $((counter - 1))"; exit 0' INT

while true; do
echo "=== Continuous Request #${counter} ==="
./send-test-request.sh 1

echo ""
echo "Request #${counter} completed. Starting next request..."
echo ""

((counter++))
done
2 changes: 1 addition & 1 deletion scripts/send-test-request.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ send_request() {

echo "Sending request ${request_num}/${COUNT}..."

curl -X POST "${URL}/tb/web_analytics?token=${TOKEN}&name=analytics_events" \
curl -X POST "${URL}/api/v1/page_hit?token=${TOKEN}&name=analytics_events" \
-H "Content-Type: application/json" \
-H "User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36" \
-H "X-Site-UUID: ${SITE_UUID}" \
Expand Down
4 changes: 2 additions & 2 deletions src/services/tinybird/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export class TinybirdClient {
}

async postEvent(event: TinybirdEvent): Promise<void> {
const url = `${this.apiUrl}/v0/events?name=${encodeURIComponent(this.datasource)}`;
const url = `${this.apiUrl}/v0/events?name=${encodeURIComponent(this.datasource)}&wait=true`;

const response = await fetch(url, {
method: 'POST',
Expand All @@ -49,7 +49,7 @@ export class TinybirdClient {
return;
}

const url = `${this.apiUrl}/v0/events?name=${encodeURIComponent(this.datasource)}`;
const url = `${this.apiUrl}/v0/events?name=${encodeURIComponent(this.datasource)}&wait=true`;

// Convert events to newline-delimited JSON format for batch insertion
const batchPayload = events.map(event => JSON.stringify(event)).join('\n');
Expand Down
14 changes: 7 additions & 7 deletions test/unit/services/tinybird/client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ describe('TinybirdClient', () => {
await client.postEvent(mockEvent);

expect(fetch).toHaveBeenCalledWith(
'https://api.tinybird.co/v0/events?name=test_datasource',
'https://api.tinybird.co/v0/events?name=test_datasource&wait=true',
{
method: 'POST',
headers: {
Expand Down Expand Up @@ -71,7 +71,7 @@ describe('TinybirdClient', () => {
await clientWithSpecialChars.postEvent({test: 'data'});

expect(fetch).toHaveBeenCalledWith(
'https://api.tinybird.co/v0/events?name=test%20datasource%20with%20spaces%20%26%20symbols',
'https://api.tinybird.co/v0/events?name=test%20datasource%20with%20spaces%20%26%20symbols&wait=true',
expect.objectContaining({
method: 'POST'
})
Expand Down Expand Up @@ -217,7 +217,7 @@ describe('TinybirdClient', () => {
await customClient.postEvent({test: 'data'});

expect(fetch).toHaveBeenCalledWith(
'https://custom.tinybird.instance.com/v0/events?name=custom_events',
'https://custom.tinybird.instance.com/v0/events?name=custom_events&wait=true',
expect.objectContaining({
headers: expect.objectContaining({
Authorization: 'Bearer custom-token'
Expand Down Expand Up @@ -267,7 +267,7 @@ describe('TinybirdClient', () => {
await client.postEventBatch(mockEvents);

expect(fetch).toHaveBeenCalledWith(
'https://api.tinybird.co/v0/events?name=test_datasource',
'https://api.tinybird.co/v0/events?name=test_datasource&wait=true',
{
method: 'POST',
headers: {
Expand Down Expand Up @@ -297,7 +297,7 @@ describe('TinybirdClient', () => {
await client.postEventBatch([mockEvent]);

expect(fetch).toHaveBeenCalledWith(
'https://api.tinybird.co/v0/events?name=test_datasource',
'https://api.tinybird.co/v0/events?name=test_datasource&wait=true',
{
method: 'POST',
headers: {
Expand Down Expand Up @@ -344,7 +344,7 @@ describe('TinybirdClient', () => {
await client.postEventBatch(largeEventBatch);

expect(fetch).toHaveBeenCalledWith(
'https://api.tinybird.co/v0/events?name=test_datasource',
'https://api.tinybird.co/v0/events?name=test_datasource&wait=true',
expect.objectContaining({
method: 'POST',
body: expect.stringContaining('batch_event')
Expand Down Expand Up @@ -383,7 +383,7 @@ describe('TinybirdClient', () => {

const expectedBody = complexEvents.map(event => JSON.stringify(event)).join('\n');
expect(fetch).toHaveBeenCalledWith(
'https://api.tinybird.co/v0/events?name=test_datasource',
'https://api.tinybird.co/v0/events?name=test_datasource&wait=true',
expect.objectContaining({
body: expectedBody
})
Expand Down