patx/mrhttp-asgi
Tests update
Commit 2bd90d1 · Mark · 2024-09-20T20:23:47-07:00
Comments
No comments yet.
Diff
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
new file mode 100644
index 0000000..6efc247
--- /dev/null
+++ b/CONTRIBUTING.md
@@ -0,0 +1,129 @@
+# Contribution Guide
+
+Thank you for coming here!
+It's always nice to have third-party contributors 🤗
+
+---
+
+# Submitting code
+
+1. If you want to add/edit/remove code, first, open an issue.
+2. Every issue, has gets it's own branch in the same repo, generally forked from `main-dev`.
+ 1. If you want your every commit displayed and discussed, push right there.
+ 2. If you want to work on something privately, fork it under your own username.
+3. For your Pull Request to pass a review, submit not just the code, but also the tests, and the documentation.
+
+
+## Git Credentials
+
+Mark sure your email is set. Github can hide your real email for you.
+
+- `git config --global user.email "YOUR_EMAIL"`
+
+## Branches
+
+- `main` for last stable version.
+- `main-dev` to synchronize the development.
+- `##-feature` branch per issue number.
+- `v1.0.0`-like branch per LTS version.
+
+## Commits
+
+- Subject (top) line is up to 50 characters.
+ - Should continue the sentence: "This commit will ...".
+ - Shouldn't end with a period.
+ - Must start with a ["verb"](#commit-verbs) or "type" or "tag".
+ - May mark the programming language in broad projects.
+- Description lines are optional and limited to 72 characters.
+ - Use the body to explain what and why vs. how. Code already answers the latter.
+ - If relevant, reference the issue at the end, using the hashtag notation.
+- If a commit can't be described with a single verb, it should be split into parts.
+
+The template would be:
+
+```txt
+<type>: <description>
+
+[optional body]
+
+[optional footer(s)]
+```
+
+An example would be:
+
+```txt
+Fix: Short (50 chars or less) summary
+
+More detailed explanatory text. Wrap it to 72 characters. The blank
+line separating the summary from the body is critical (unless you omit
+the body entirely).
+
+Write your commit message in the imperative: "Fix bug" and not "Fixed
+bug" or "Fixes bug." This convention matches up with commit messages
+generated by commands like git merge and git revert.
+
+Further paragraphs come after blank lines.
+
+- Bullet points are okay, too.
+- Typically a hyphen or asterisk is used for the bullet, followed by a
+ single space. Use a hanging indent.
+```
+
+### Commit Verbs
+
+We agree on a short list of leading active verbs for the subject line, similar to the [ESLint convention](https://github.com/conventional-changelog/conventional-changelog/tree/master/packages/conventional-changelog-eslint).
+
+| Verbs | Part | When? |
+| :------- | :-----: | :----------------------------------- |
+| Refactor | - | Non-user facing changes |
+| Test | - | Updates **only** to tests |
+| Docs | - | Updates **only** to documentation |
+| Build | - | Compilation fixes |
+| | | |
+| Make | `patch` | New compilation settings, or configs |
+| Fix | `patch` | Bug fixes |
+| Improve | `patch` | Small enhancement |
+| Upgrade | `patch` | Updating a dependency version |
+| | | |
+| Add | `minor` | New feature |
+| | | |
+| Breaking | `major` | Backwards-incompatible update |
+
+Which is a well known, widely adopted set, and self-explanatory set.
+
+### Why Use Conventional Commits?
+
+- Automatically generating CHANGELOGs.
+- Automatically determining a semantic version bump (based on the types of commits landed).
+- Communicating the nature of changes to teammates, the public, and other stakeholders.
+- Triggering build and publish processes.
+- Making it easier for people to contribute to your projects, by allowing them to explore a more structured commit history.
+
+
+## Automated Semantic Versioning
+
+- Every repo has a root level `VERSION` file.
+- Contents are `major.minor.patch` followed by newline.
+- CI tools will automatically generate a `CHANGELOG.md` and release notes.
+
+We use a variation of **[Semantic Versioning](https://semver.org/)**.
+
+> [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/) specification.
+
+## Libraries and Dependencies
+
+- Check that your [licenses](#licensing) are compatible.
+- Prefer dependencies, that are actively maintained, tested, and documented.
+- Prefer projects using the same build system.
+
+Choosing dependencies is much harder than it seems.
+Those rules can be skipped or bended.
+For example, many teams may not consider using projects with less than 1'000 stars on GitHub.
+Yet some of the [cleanest](https://github.com/pierresegonne/funky-attractors) and coolest repositories I have seen, have exactly **zero** stars.
+Being cautious is a good baselines, but if you want to be competitive, you have to take risks.
+
+## Code
+
+- No trailing whitespaces.
+- Every file must end with newline.
+
diff --git a/dotests.py b/dotests.py
index c0215ff..f80ada7 100644
--- a/dotests.py
+++ b/dotests.py
@@ -8,9 +8,12 @@ readme = """
mrworkserver
python workserver.py
+
+TODO Check for mrworkserver and mrcache being up and skip if they aren't available
"""
+
import pkgutil, time
import inspect
import types
@@ -29,10 +32,6 @@ import uvloop
import psutil
import atexit
-# TODO
-# Check for mrworkserver and mrcache being up and add the session key so we hit and load the json 43709dd361cc443e976b05714581a7fb
-# mrcache -m 64 -i 16
-# python mrworkserver/tst.py
async def run_tests():
@@ -155,7 +154,6 @@ async def run_benchmarks():
await proc.wait()
async def main():
- print("main")
await run_tests()
await run_benchmarks()
diff --git a/gbench/readme b/gbench/readme
index 03d21d5..9c78a3b 100644
--- a/gbench/readme
+++ b/gbench/readme
@@ -8,6 +8,10 @@ Test code first:
https://github.com/google/benchmark
+g++ -O3 -march=znver4 -mavx512bf16 -lbenchmark -lpthread -isystem benchmark/include -Lbenchmark/build/src -o bm bm.c
+
+
+
Install gbench
sudo apt install cmake
git clone https://github.com/google/benchmark.git
diff --git a/tests/readme b/tests/readme
index 271d3c3..995e067 100644
--- a/tests/readme
+++ b/tests/readme
@@ -1,10 +1,6 @@
-Start this up to run the tests -- have in automatically done?
- mrcache -m 64 -i 16
- python load_session.py will load the test user session
+Start this up to run the tests . TODO Skip if mrcache is not available
-set methods on pages
-test not returning a string from a page ( regular and coro )
-test pipeline coro
+ mrcache -m 64 -i 16
+ python load_session.py # will load the test user session
-redirect.py make tests url and code
diff --git a/tests/s1.py b/tests/s_main.py
similarity index 89%
rename from tests/s1.py
rename to tests/s_main.py
index 268f9b3..ceb9286 100644
--- a/tests/s1.py
+++ b/tests/s_main.py
@@ -5,9 +5,10 @@ import socket
import mrjson as json
app = Application()
-app.config["memcache"] = [ ("127.0.0.1", 11211) ]
-app.config["mrcache"] = [("127.0.0.1", 7000 )]
-app.session_backend = "mrcache"
+
+#app.config["memcache"] = [ ("127.0.0.1", 11211) ]
+#app.config["mrcache"] = [("127.0.0.1", 7000 )]
+#app.session_backend = "mrcache"
@app.route('/',_type='text')
def index(r):
@@ -110,12 +111,6 @@ def parseFiles(r):
if r.files == None: return "No files"
return r.files[0]["body"]
[email protected]('/s',options=['session'])
-def session(r):
- if r.user:
- return "session"
- return "session"
-
@app.route('/noreturn')
def noreturn(r):
pass
diff --git a/tests/s_resp.py b/tests/s_resp.py
index d00576d..bb4f7f9 100644
--- a/tests/s_resp.py
+++ b/tests/s_resp.py
@@ -40,10 +40,10 @@ def cook2(r):
return 'cookie'
-# python requests can't handle this?? Hangs waiting for response curl is fine
+# python requests can't handle this?? Hangs waiting for response. curl is fine
#@app.route('/long', _type='text')
#def longresp(r):
- #return "fart"*128*1000
+ #return "longresp"*64*1000
app.run(cores=1)
diff --git a/tests/s_session.py b/tests/s_session.py
new file mode 100644
index 0000000..faa4eed
--- /dev/null
+++ b/tests/s_session.py
@@ -0,0 +1,18 @@
+from mrhttp import app
+
+app.config["memcache"] = [ ("127.0.0.1", 11211) ]
+app.config["mrcache"] = [("127.0.0.1", 7000 )]
+app.session_backend = "mrcache"
+
[email protected]('/',_type='text')
+def index(r):
+ return 'Hello World!'
+
[email protected]('/s',options=['session'])
+def session(r):
+ if r.user:
+ return "session"
+ return "no session"
+
+app.run(cores=1)
+
diff --git a/tests/server.py b/tests/server.py
deleted file mode 100644
index 85ed485..0000000
--- a/tests/server.py
+++ /dev/null
@@ -1,35 +0,0 @@
-from mrhttp import Application
-from mrhttp import Request
-import mrhttp
-import socket
-
-app = Application()
-
-
[email protected]('/')
-def index():
- return 'Hello World!'
-
[email protected]('/foo')
-def foo():
- return 'foo'
-
[email protected]('/123456789012345678901234567890/testing')
-def testing():
- return 'Hello World!'
-
[email protected]('/404/')
-def notFound():
- raise mrhttp.HTTPError(404)
- return 'Hello World!'
-
[email protected]('/foo/{}')
-def foo1(foo):
- return 'Hello World!'
-
[email protected]('/foo/{}/{}')
-def foo2(foo, bar):
- return 'Hello World!'
-
-app.run(cores=1)
-
diff --git a/tests/test_exceptions.py b/tests/test_exceptions.py
index 08676c6..5d4a7ea 100644
--- a/tests/test_exceptions.py
+++ b/tests/test_exceptions.py
@@ -9,7 +9,7 @@ server = None
def setup():
print("Begin test_exceptions")
global server
- server = tests.common.start_server("tests/s1.py")
+ server = tests.common.start_server("tests/s_main.py")
if not server:
return 1
return 0
diff --git a/tests/test_requests.py b/tests/test_requests.py
index 5eb80a9..36b9b68 100644
--- a/tests/test_requests.py
+++ b/tests/test_requests.py
@@ -36,7 +36,7 @@ server = None
def setup():
print("Begin test_requests")
global server
- server = tests.common.start_server("tests/s1.py")
+ server = tests.common.start_server("tests/s_main.py")
if not server:
return 1
return 0
@@ -143,10 +143,10 @@ def test_one():
eq(r.status_code, 200)
eq(r.text, '{"long":"' + s + '"}')
- # Sessions
- cookie = {'mrsession': '43709dd361cc443e976b05714581a7fb'}
- r = requests.post('http://localhost:8080/s', cookies=cookie)
- eq(r.text, "session")
+ # Sessions TODO Moved to test_session.py
+ #cookie = {'mrsession': '43709dd361cc443e976b05714581a7fb'}
+ #r = requests.post('http://localhost:8080/s', cookies=cookie)
+ #eq(r.text, "session")
# Misc
r = requests.get('http://localhost:8080/printIP')
diff --git a/tests/test_response.py b/tests/test_response.py
index 673e54e..f8bd9f8 100644
--- a/tests/test_response.py
+++ b/tests/test_response.py
@@ -43,7 +43,6 @@ def test_one():
def teardown():
- print("teardown")
global server
stop_server(server)
#server.terminate()
diff --git a/tests/test_session.py b/tests/test_session.py
new file mode 100644
index 0000000..d2eba95
--- /dev/null
+++ b/tests/test_session.py
@@ -0,0 +1,29 @@
+
+import tests.common
+import requests
+import mrpacker
+from tests.common import eq,contains,stop_server
+
+server = None
+def setup():
+ print("Begin test_session")
+ global server
+ server = tests.common.start_server("tests/s_session.py")
+ if not server:
+ return 1
+ return 0
+
+
+def test_one():
+
+ # TODO login and check session
+
+ cookie = {'mrsession': '43709dd361cc443e976b05714581a7fb'}
+ r = requests.post('http://localhost:8080/s', cookies=cookie)
+ eq(r.text, "session")
+
+def teardown():
+ global server
+ stop_server(server)
+ #server.terminate()
+
diff --git a/tests/up.py b/tests/up.py
deleted file mode 100644
index c8e00be..0000000
--- a/tests/up.py
+++ /dev/null
@@ -1,5 +0,0 @@
-import requests
-
-with open('delme', 'r') as f:
- files = {"data": f}
- requests.post(f'http://localhost:8080/', files=files)
diff --git a/tests/z b/tests/z
deleted file mode 100644
index de98044..0000000
--- a/tests/z
+++ /dev/null
@@ -1,3 +0,0 @@
-a
-b
-c
diff --git a/tests/zz b/tests/zz
deleted file mode 100644
index d70f6df..0000000
--- a/tests/zz
+++ /dev/null
@@ -1,4 +0,0 @@
-1
-2
-3
-