Skip to content

Commit 29db774

Browse files
committed
Remove comments, more delay for test
Signed-off-by: Nijat K <[email protected]>
1 parent 628ceb6 commit 29db774

File tree

5 files changed

+26
-112
lines changed

5 files changed

+26
-112
lines changed

Makefile

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ build-debug: ## build the library ( DEBUG ) - May need a make clean when switch
2424
SKBUILD_CONFIGURE_OPTIONS="" DEBUG=1 python setup.py build build_ext --inplace
2525

2626
build-conda: ## build the library in Conda
27-
CSP_USE_CCACHE=0 python setup.py build build_ext --csp-no-vcpkg --inplace
27+
python setup.py build build_ext --csp-no-vcpkg --inplace
2828

2929
install: ## install library
3030
python -m pip install .
@@ -83,7 +83,7 @@ checks: check
8383

8484
TEST_ARGS :=
8585
test-py: ## Clean and Make unit tests
86-
python -m pytest -vv -s csp/tests --junitxml=junit.xml $(TEST_ARGS)
86+
python -m pytest -v csp/tests --junitxml=junit.xml $(TEST_ARGS)
8787

8888
test-cpp: ## Make C++ unit tests
8989
ifneq ($(OS),Windows_NT)

cpp/csp/engine/StatusAdapter.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class StatusAdapter : public PushInputAdapter
4444
m_statusAccess.meta = meta;
4545
m_statusAccess.level = meta -> getMetaField<int64_t>( "level", "Status" );
4646
m_statusAccess.statusCode = meta -> getMetaField<int64_t>( "status_code", "Status" );
47-
m_statusAccess.msg = meta -> getMetaField<typename csp::StringStructField::CType>( "msg", "Status" );
47+
m_statusAccess.msg = meta -> getMetaField<std::string>( "msg", "Status" );
4848
}
4949

5050
void pushStatus( int64_t level, int64_t statusCode, const std::string & msg, PushBatch *batch = nullptr )

cpp/csp/engine/Struct.h

+18-81
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
#include <string>
88
#include <vector>
99
#include <unordered_map>
10-
#include <iostream>
1110

1211
namespace csp
1312
{
@@ -669,69 +668,16 @@ class StructMeta : public std::enable_shared_from_this<StructMeta>
669668
};
670669

671670
template<typename T>
672-
std::shared_ptr<typename StructField::upcast<T>::type> StructMeta::getMetaField(const char* fieldname, const char* expectedtype) {
673-
std::cout << "\n=== getMetaField Debug ===\n";
674-
std::cout << "1. Looking for field: " << fieldname << "\n";
675-
676-
auto field_ = field(fieldname);
677-
if(!field_) {
678-
std::cout << "2. Field not found!\n";
679-
CSP_THROW(TypeError, "Struct type " << name() << " missing required field " << fieldname);
680-
}
681-
682-
std::cout << "2. Field found\n";
683-
std::cout << "3. Field name from object: " << field_->fieldname() << "\n";
684-
std::cout << "4. Field type from CspType: " << field_->type()->type() << "\n";
685-
std::cout << "5. Expected type: " << CspType::Type::fromCType<T>::type << "\n";
686-
687-
// Memory layout & pointer checks
688-
const StructField* field_ptr = field_.get();
689-
std::cout << "6. Field ptr value: " << field_ptr << "\n";
690-
std::cout << "7. Field use count: " << field_.use_count() << "\n";
691-
692-
// Detailed field information
693-
if(field_ptr) {
694-
std::cout << "8. Field metadata:\n";
695-
std::cout << " - Field offset: " << field_ptr->offset() << "\n";
696-
std::cout << " - Field size: " << field_ptr->size() << "\n";
697-
std::cout << " - Field alignment: " << field_ptr->alignment() << "\n";
698-
std::cout << " - Field mask offset: " << field_ptr->maskOffset() << "\n";
699-
std::cout << " - Field mask bit: " << static_cast<int>(field_ptr->maskBit()) << "\n";
700-
701-
// Type verification
702-
std::cout << "9. Type checks:\n";
703-
std::cout << " - Original type: " << typeid(field_).name() << "\n";
704-
std::cout << " - Target type: " << typeid(typename StructField::upcast<T>::type).name() << "\n";
705-
std::cout << " - Is native: " << field_ptr->isNative() << "\n";
706-
707-
// Test various casts
708-
std::cout << "10. Detailed cast tests:\n";
709-
std::cout << " Base classes:\n";
710-
std::cout << " - As StructField*: " << (dynamic_cast<const StructField*>(field_ptr) != nullptr) << "\n";
711-
std::cout << " - As NonNativeStructField*: " << (dynamic_cast<const NonNativeStructField*>(field_ptr) != nullptr) << "\n";
712-
std::cout << " Non-native implementations:\n";
713-
std::cout << " - As StringStructField*: " << (dynamic_cast<const StringStructField*>(field_ptr) != nullptr) << "\n";
714-
std::cout << " - As DialectGenericStructField*: " << (dynamic_cast<const DialectGenericStructField*>(field_ptr) != nullptr) << "\n";
715-
std::cout << " - As ArrayStructField<std::string>*: " << (dynamic_cast<const ArrayStructField<std::vector<std::string>>*>(field_ptr) != nullptr) << "\n";
716-
std::cout << " Native field test:\n";
717-
std::cout << " - As NativeStructField<int64_t>*: " << (dynamic_cast<const NativeStructField<int64_t>*>(field_ptr) != nullptr) << "\n";
718-
}
719-
720-
using TargetType = typename StructField::upcast<T>::type;
721-
auto typedfield = std::dynamic_pointer_cast<TargetType>(field_);
722-
std::cout << "11. Final dynamic_cast result: " << (typedfield ? "success" : "failure") << "\n";
671+
std::shared_ptr<typename StructField::upcast<T>::type> StructMeta::getMetaField( const char * fieldname, const char * expectedtype )
672+
{
673+
auto field_ = field( fieldname );
674+
if( !field_ )
675+
CSP_THROW( TypeError, "Struct type " << name() << " missing required field " << fieldname << " for " << expectedtype );
723676

724-
if(!typedfield) {
725-
std::cout << "12. FAILED CAST DETAILS:\n";
726-
std::cout << " - Source type: " << typeid(StructField).name() << "\n";
727-
std::cout << " - Target type: " << typeid(TargetType).name() << "\n";
728-
729-
CSP_THROW(TypeError, expectedtype << " - provided struct type " << name()
730-
<< " expected type " << CspType::Type::fromCType<T>::type
731-
<< " for field " << fieldname
732-
<< " but got type " << field_->type()->type()
733-
<< " for " << expectedtype);
734-
}
677+
std::shared_ptr<typename StructField::upcast<T>::type> typedfield = std::dynamic_pointer_cast<typename StructField::upcast<T>::type>( field_ );
678+
if( !typedfield )
679+
CSP_THROW( TypeError, expectedtype << " - provided struct type " << name() << " expected type " << CspType::Type::fromCType<T>::type << " for field " << fieldname
680+
<< " but got type " << field_ -> type() -> type() << " for " << expectedtype );
735681

736682
return typedfield;
737683
}
@@ -827,31 +773,22 @@ class Struct
827773
friend class StructMeta;
828774

829775
//Note these members are not included on size(), they're stored before "this" ptr ( see operator new / delete )
830-
struct alignas(8) HiddenData {
831-
alignas(8) size_t refcount; // 8 bytes at 0x0
832-
alignas(8) std::shared_ptr<const StructMeta> meta; // 16 bytes at 0x8
833-
alignas(8) void* dialectPtr; // 8 bytes at 0x18
834-
// Total: 32 bytes
776+
struct HiddenData
777+
{
778+
size_t refcount;
779+
std::shared_ptr<const StructMeta> meta;
780+
void * dialectPtr;
835781
};
836782

837783
const HiddenData * hidden() const
838784
{
839785
return const_cast<Struct *>( this ) -> hidden();
840786
}
841787

842-
static constexpr size_t HIDDEN_OFFSET = 32; // sizeof(HiddenData) aligned to 8 bytes
843-
844-
HiddenData* hidden() {
845-
std::byte* base = reinterpret_cast<std::byte*>(this);
846-
// Force alignment to match shared_ptr requirements
847-
static_assert(alignof(HiddenData) >= alignof(std::shared_ptr<void>),
848-
"HiddenData must be aligned for shared_ptr");
849-
return reinterpret_cast<HiddenData*>(base - HIDDEN_OFFSET);
850-
}
851-
// HiddenData * hidden()
852-
// {
853-
// return reinterpret_cast<HiddenData *>( reinterpret_cast<uint8_t *>( this ) - sizeof( HiddenData ) );
854-
// }
788+
HiddenData * hidden()
789+
{
790+
return reinterpret_cast<HiddenData *>( reinterpret_cast<uint8_t *>( this ) - sizeof( HiddenData ) );
791+
}
855792

856793
//actual data is allocated past this point
857794
};

cpp/csp/python/adapters/websocketadapterimpl.cpp

-16
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
#include <csp/python/PyInputAdapterWrapper.h>
99
#include <csp/python/PyOutputAdapterWrapper.h>
1010

11-
#include <iostream>
1211
using namespace csp::adapters::websocket;
1312

1413
namespace csp::python
@@ -63,30 +62,15 @@ static OutputAdapter * create_websocket_header_update_adapter( csp::AdapterManag
6362

6463
static OutputAdapter * create_websocket_connection_request_adapter( csp::AdapterManager * manager, PyEngine * pyengine, PyObject * args )
6564
{
66-
// std::cout << "hereeeee33ee" << "\n";
6765
PyObject * pyProperties;
68-
// PyObject * type;
6966
auto * websocketManager = dynamic_cast<ClientAdapterManager*>( manager );
7067
if( !websocketManager )
7168
CSP_THROW( TypeError, "Expected WebsocketClientAdapterManager" );
7269

7370
if( !PyArg_ParseTuple( args, "O!",
7471
&PyDict_Type, &pyProperties ) )
7572
CSP_THROW( PythonPassthrough, "" );
76-
// std::cout << "hereeeee334444ee" << "\n";
7773
return websocketManager -> getConnectionRequestAdapter( fromPython<Dictionary>( pyProperties ) );
78-
79-
80-
// TODO
81-
// Here I think we should have a websocket connection manager
82-
// that will handle the connections and endpoint management
83-
// It will create the connection request output adapter
84-
// That output adapter, when it ticks, with a list of python Dictionary
85-
// will then use the boost beast 'post' function to schedule, on the
86-
// io context, a callback to process that dict (on the websocket connection manager!!!) and handle the endpoint manipulation appropriately
87-
88-
// that websocket connection manager will run the thread with the io context
89-
// being run. Move it away from clientAdapterManager
9074
}
9175

9276
REGISTER_ADAPTER_MANAGER( _websocket_adapter_manager, create_websocket_adapter_manager );

csp/tests/adapters/test_websocket.py

+5-12
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ def create_tornado_server(port: int = None):
5858
def run_io_loop():
5959
nonlocal io_loop, app
6060
io_loop = tornado.ioloop.IOLoop()
61-
io_loop.make_current()
6261
app = tornado.web.Application([(r"/", EchoWebsocketHandler)])
6362
try:
6463
app.listen(port)
@@ -303,7 +302,7 @@ def g():
303302
)
304303
val = csp.curve(int, [(timedelta(milliseconds=50), 0), (timedelta(milliseconds=500), 1)])
305304
hello = csp.apply(val, lambda x: f"hi world{x}", str)
306-
delayed_conn_req = csp.delay(conn_request, delay=timedelta(milliseconds=100))
305+
delayed_conn_req = csp.delay(conn_request, delay=timedelta(milliseconds=200))
307306

308307
# We connect immediately and send out the hello message
309308
ws.send(hello, connection_request=conn_request)
@@ -328,12 +327,6 @@ def g():
328327

329328
@pytest.mark.parametrize("reconnect_immeditately", [False, True])
330329
def test_dynamic_disconnect_connect_pruned_subscribe(self, reconnect_immeditately):
331-
@csp.node
332-
def prevent_prune(objs: ts[str]):
333-
if csp.ticked(objs):
334-
# Does nothing but makes sure it's not pruned
335-
...
336-
337330
@csp.graph
338331
def g():
339332
ws = WebsocketAdapterManager(dynamic=True)
@@ -354,7 +347,7 @@ def g():
354347
disconnect_reqs,
355348
),
356349
(
357-
timedelta(milliseconds=350),
350+
timedelta(milliseconds=400),
358351
[
359352
ConnectionRequest(
360353
uri=f"ws://localhost:{self.port}/",
@@ -365,7 +358,7 @@ def g():
365358
],
366359
)
367360
const_conn_request = csp.const([ConnectionRequest(uri=f"ws://localhost:{self.port}/")])
368-
val = csp.curve(int, [(timedelta(milliseconds=100, microseconds=1), 0), (timedelta(milliseconds=500), 1)])
361+
val = csp.curve(int, [(timedelta(milliseconds=200, microseconds=1), 0), (timedelta(milliseconds=500), 1)])
369362
hello = csp.apply(val, lambda x: f"hi world{x}", str)
370363

371364
# We connect immediately and send out the hello message
@@ -382,7 +375,7 @@ def g():
382375
recv4 = ws.subscribe(
383376
str,
384377
RawTextMessageMapper(),
385-
connection_request=csp.const([no_persist_conn], delay=timedelta(milliseconds=250)),
378+
connection_request=csp.const([no_persist_conn], delay=timedelta(milliseconds=300)),
386379
)
387380

388381
csp.add_graph_output("recv", recv)
@@ -431,7 +424,7 @@ def g():
431424
)
432425
val = csp.curve(int, [(timedelta(milliseconds=50), 0), (timedelta(milliseconds=500), 1)])
433426
hello = csp.apply(val, lambda x: f"hi world{x}", str)
434-
delayed_conn_req = csp.delay(conn_request, delay=timedelta(milliseconds=100))
427+
delayed_conn_req = csp.delay(conn_request, delay=timedelta(milliseconds=200))
435428

436429
# We connect immediately and send out the hello message
437430
ws.send(hello, connection_request=conn_request)

0 commit comments

Comments
 (0)