Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correctness Test #39

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
50 changes: 50 additions & 0 deletions tests/service/test_server_state_machine.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import os
import tempfile

from typing import Dict, Optional, Union
import hypothesis.strategies as st
from hypothesis.stateful import Bundle, RuleBasedStateMachine, rule

from memtable import Memtable, TOMBSTONE

from fastapi.testclient import TestClient
from service.main import app


class ServerDictComparison(RuleBasedStateMachine):
def __init__(self):
super().__init__()
self.client = TestClient(app)
self.model: Dict[str, Optional[str]] = dict()

keys = Bundle("keys")
values = Bundle("values")

@rule(target=keys, key=st.text(min_size=1))
def add_key(self, key: str):
return key

@rule(target=values, value=st.text())
def add_value(self, value: str):
return value

@rule(key=keys, value=values)
def set(self, key: str, value: str):
self.model[key] = value
self.client.put(f"/kvs?key={key}&value={value}")

@rule(key=keys)
def unset(self, key: str):
self.model[key] = None
self.client.delete(f"/kvs?key={key}")

@rule(key=keys)
def values_agree(self, key: str):
res = self.client.get(f"/kvs/{key}")
if res.status_code == 404:
assert self.model.get(key, None) == None
else:
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added the else here, since our service returns a JSON message when a key is not found, instead of None.

assert res.text == self.model.get(key, None)


TestServer = ServerDictComparison.TestCase