Skip to content

Commit

Permalink
integration tests: add basic test for php, python and pypy plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
niol committed Sep 9, 2024
1 parent 46bb9e1 commit 8604c46
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 4 deletions.
8 changes: 6 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,18 @@ jobs:
run: make unittests

test:
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
steps:
- name: Install dependencies
run: |
sudo apt update -qq
sudo apt install --no-install-recommends -qqyf \
libpcre2-dev libjansson-dev libcap2-dev
libpcre2-dev libjansson-dev libcap2-dev \
php-dev libphp-embed libargon2-dev libsodium-dev \
pypy3
- uses: actions/checkout@v4
- name: Set env
run: echo "PROFILE=integration-tests" >> $GITHUB_ENV
- name: Run integration tests
run: make all tests

Expand Down
4 changes: 4 additions & 0 deletions buildconf/integration-tests.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[uwsgi]
inherit = base
main_plugin =
plugins = python,php,pypy
3 changes: 3 additions & 0 deletions t/php/config.ini
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
[uwsgi]
http-socket = :8080
http-socket-modifier1 = 14
# required for php
need-app = false
plugins = php

cache2 = name=session,items=1000,store=/tmp/uwsgi-session-cache,bitmap=1

Expand Down
7 changes: 7 additions & 0 deletions t/pypy/config.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[uwsgi]
plugin = pypy
need-app = false
pypy-lib = /usr/lib/libpypy3-c.so
pypy-home = /usr/lib/pypy3
pypy-setup = plugins/pypy/pypy_setup.py
pypy-wsgi-file = t/python/helloapp.py
3 changes: 3 additions & 0 deletions t/python/helloapp.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
def application(env, start_response):
start_response("200 OK", [("Content-Type", "text/html")])
return [b"Hello World"]
48 changes: 46 additions & 2 deletions t/runner
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
#!/usr/bin/python3
#
# This test suite runner runs some integration tests for uwsgi, that is
# each test launches a test server with a specific configuration and
# verifies (usually using a HTTP request) that this test server behaves as
# expected.
#
# buildconf/integration-tests.ini holds the build configuration for this
# to run fine.


import os
Expand Down Expand Up @@ -82,19 +90,55 @@ class UwsgiTest(unittest.TestCase):
self.testserver.wait()
self.testserver.stdout.close()

@unittest.skipUnless(*plugins_available(["python3"]))
@unittest.skipUnless(*plugins_available(["python"]))
def test_static_expires(self):
self.start_listen_server(
[
"--plugin",
"python3", # provide a request plugin if no embedded request plugin
"python", # provide a request plugin
os.path.join(TESTS_DIR, "static", "config.ini"),
]
)

with requests.get(f"http://{UWSGI_HTTP}/foobar/config.ini") as r:
self.assertTrue("Expires" in r.headers)

@unittest.skipUnless(*plugins_available(["python"]))
def test_python3_helloworld(self):
self.start_listen_server(
[
"--plugin",
"python",
"--wsgi-file",
os.path.join(TESTS_DIR, "python", "helloapp.py"),
]
)

with requests.get(f"http://{UWSGI_HTTP}/") as r:
self.assertEqual(r.text, "Hello World")

@unittest.skipUnless(*plugins_available(["pypy"]))
def test_pypy3_helloworld(self):
self.start_listen_server(
[
os.path.join(TESTS_DIR, "pypy", "config.ini"),
]
)

with requests.get(f"http://{UWSGI_HTTP}/") as r:
self.assertEqual(r.text, "Hello World")

@unittest.skipUnless(*plugins_available(["php"]))
def test_php_session(self):
self.start_listen_server(
[
os.path.join(TESTS_DIR, "php", "config.ini"),
]
)

with requests.get(f"http://{UWSGI_HTTP}/test.php") as r:
self.assertEqual(r.text, "PASS\n")


if __name__ == "__main__":
unittest.main()

0 comments on commit 8604c46

Please sign in to comment.