Skip to content

Commit

Permalink
move RPS endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
Archmonger committed Jul 13, 2023
1 parent f77c5e8 commit 52be745
Show file tree
Hide file tree
Showing 8 changed files with 131 additions and 19 deletions.
18 changes: 0 additions & 18 deletions tests/test_app/components.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import asyncio
import inspect
from datetime import datetime
from pathlib import Path

from channels.db import database_sync_to_async
Expand All @@ -25,23 +24,6 @@
from .types import TestObject


@component
def test_runner():
start_time, _ = hooks.use_state(datetime.now())
count, set_count = hooks.use_state(0)
seconds_elapsed = (datetime.now() - start_time).total_seconds()

@hooks.use_effect
def run_tests():
set_count(count + 1)

return html.div(
{"id": "test-runner"},
html.div(f"Total renders: {count}"),
html.div(f"Renders Per Second: {count / (seconds_elapsed or 0.01)}"),
)


@component
def hello_world():
return html._(html.div({"id": "hello-world"}, "Hello World!"))
Expand Down
Empty file.
23 changes: 23 additions & 0 deletions tests/test_app/performance/components.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from datetime import datetime

from reactpy import component, hooks, html


@component
def renders_per_second():
start_time, _ = hooks.use_state(datetime.now())
count, set_count = hooks.use_state(0)
seconds_elapsed = (datetime.now() - start_time).total_seconds()

@hooks.use_effect
def run_tests():
set_count(count + 1)

return html.div(
{"id": "test-runner"},
html.div(f"Total renders: {count}"),
html.div(
{"class_name": "rps"},
f"Renders Per Second: {count / (seconds_elapsed or 0.01)}",
),
)
7 changes: 7 additions & 0 deletions tests/test_app/performance/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from django.urls import path

from .views import renders_per_second

urlpatterns = [
path("rps/", renders_per_second),
]
5 changes: 5 additions & 0 deletions tests/test_app/performance/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from django.shortcuts import render


def renders_per_second(request):
return render(request, "renders_per_second.html", {})
71 changes: 70 additions & 1 deletion tests/test_app/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,76 @@
<body>
<h1>ReactPy Test Page</h1>
<hr>
{% component "test_app.components.test_runner" %}
{% component "test_app.components.hello_world" class="hello-world" %}
<hr>
{% component "test_app.components.button" class="button" %}
<hr>
{% component "test_app.components.parameterized_component" class="parametarized-component" x=123 y=456 %}
<hr>
{% component "test_app.components.object_in_templatetag" my_object %}
<hr>
{% component "test_app.components.simple_button" %}
<hr>
{% component "test_app.components.use_connection" %}
<hr>
{% component "test_app.components.use_scope" %}
<hr>
{% component "test_app.components.use_location" %}
<hr>
{% component "test_app.components.use_origin" %}
<hr>
{% component "test_app.components.django_css" %}
<hr>
{% component "test_app.components.django_js" %}
<hr>
{% component "test_app.components.unauthorized_user" %}
<hr>
{% component "test_app.components.authorized_user" %}
<hr>
{% component "test_app.components.relational_query" %}
<hr>
{% component "test_app.components.async_relational_query" %}
<hr>
{% component "test_app.components.todo_list" %}
<hr>
{% component "test_app.components.async_todo_list" %}
<hr>
{% component "test_app.components.view_to_component_sync_func" %}
<hr>
{% component "test_app.components.view_to_component_async_func" %}
<hr>
{% component "test_app.components.view_to_component_sync_class" %}
<hr>
{% component "test_app.components.view_to_component_async_class" %}
<hr>
{% component "test_app.components.view_to_component_template_view_class" %}
<hr>
{% component "test_app.components.view_to_component_script" %}
<hr>
{% component "test_app.components.view_to_component_request" %}
<hr>
{% component "test_app.components.view_to_component_args" %}
<hr>
{% component "test_app.components.view_to_component_kwargs" %}
<hr>
{% component "test_app.components.view_to_component_sync_func_compatibility" %}
<hr>
{% component "test_app.components.view_to_component_async_func_compatibility" %}
<hr>
{% component "test_app.components.view_to_component_sync_class_compatibility" %}
<hr>
{% component "test_app.components.view_to_component_async_class_compatibility" %}
<hr>
{% component "test_app.components.view_to_component_template_view_class_compatibility" %}
<hr>
{% component "test_app.components.view_to_component_decorator" %}
<hr>
{% component "test_app.components.view_to_component_decorator_args" %}
<hr>
<div id="component_does_not_exist_error">{% component "test_app.components.does_not_exist" %}</div>
<hr>
<div id="component_param_error">{% component "test_app.components.hello_world" invalid_param="random_value" %}</div>
<hr>
</body>

</html>
25 changes: 25 additions & 0 deletions tests/test_app/templates/renders_per_second.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{% load static %} {% load reactpy %}
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="shortcut icon" type="image/png" href="{% static 'favicon.ico' %}" />
<title>ReactPy</title>
<style>
iframe {
width: 100%;
height: 45px;
}
</style>
</head>

<body>
<h1>ReactPy Renders Per Second Test Page</h1>
<hr>
{% component "test_app.performance.components.renders_per_second" %}
</body>

</html>
1 change: 1 addition & 0 deletions tests/test_app/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class AccessUser:

urlpatterns = [
path("", base_template),
path("performance/", include("test_app.performance.urls")),
path("reactpy/", include("reactpy_django.http.urls")),
path("admin/", admin.site.urls),
]

0 comments on commit 52be745

Please sign in to comment.