@@ -11,209 +11,3 @@ def test_import_succeeds() -> None:
1111 from dbt_core_interface import project
1212
1313 _ = project
14-
15-
16- def test_list ():
17- """Test the list method of the project module.
18-
19- This validates project parsing and the ability to list nodes.
20- """
21- from dbt_core_interface .project import DbtProject
22-
23- project = DbtProject (
24- project_dir = "demo_duckdb" ,
25- profiles_dir = "demo_duckdb" ,
26- target = "dev" ,
27- )
28- nodes = project .list ("*" )
29- assert len (nodes ) == 28
30-
31-
32- def test_server ():
33- """Some quick and dirty functional tests for the server.
34-
35- This is not a comprehensive test suite, but it does test the server's ability to
36- handle multiple clients and multiple projects simultaneously as well as WSGI compliance.
37- It also touches lots of the codebase, so it's a good sanity check.
38- """
39- import json
40- import random
41- import time
42- from concurrent .futures import ThreadPoolExecutor
43-
44- from webtest import TestApp
45-
46- from dbt_core_interface .project import (
47- DbtInterfaceServerPlugin ,
48- JSONPlugin ,
49- __dbt_major_version__ ,
50- __dbt_minor_version__ ,
51- app ,
52- install ,
53- server_serializer ,
54- )
55-
56- install (DbtInterfaceServerPlugin ())
57- install (JSONPlugin (json_dumps = lambda body : json .dumps (body , default = server_serializer )))
58- client = TestApp (app .default )
59-
60- SIMULATED_CLIENTS = 50 # noqa: N806
61- DUCKDB_PROJECTS = [ # noqa: N806
62- "j_shop_1_duckdb" ,
63- "j_shop_2_duckdb" ,
64- "h_niceserver_1_duckdb" ,
65- "h_niceserver_2_duckdb" ,
66- ]
67- SQLITE_PROJECTS = (
68- [ # noqa: N806
69- "j_shop_1_sqlite" ,
70- "j_shop_2_sqlite" ,
71- "j_shop_3_sqlite" ,
72- "j_shop_4_sqlite" ,
73- "h_niceserver_1_sqlite" ,
74- ]
75- if (__dbt_major_version__ , __dbt_minor_version__ ) < (1 , 8 )
76- else []
77- ) # SQLITE adapter is not supported in dbt 1.8+ yet: https://github.com/codeforkjeff/dbt-sqlite/issues
78- PROJECTS = DUCKDB_PROJECTS + SQLITE_PROJECTS # noqa: N806
79-
80- for proj in SQLITE_PROJECTS :
81- register_response = client .post (
82- "/register" ,
83- params = json .dumps (
84- {
85- "project_dir" : "demo_sqlite" ,
86- "profiles_dir" : "demo_sqlite" ,
87- "target" : "dev" ,
88- }
89- ),
90- headers = {"X-dbt-Project" : proj },
91- content_type = "application/json" ,
92- status = "*" ,
93- )
94- print (register_response )
95- for proj in DUCKDB_PROJECTS :
96- register_response = client .post (
97- "/register" ,
98- params = json .dumps (
99- {
100- "project_dir" : "./demo_duckdb" ,
101- "profiles_dir" : "./demo_duckdb" ,
102- "target" : "dev" ,
103- }
104- ),
105- headers = {"X-dbt-Project" : proj },
106- content_type = "application/json" ,
107- status = "*" ,
108- )
109- print (register_response )
110-
111- e = ThreadPoolExecutor (max_workers = SIMULATED_CLIENTS )
112-
113- STATEMENT = r"""
114- {{% set payment_methods = ['credit_card', 'coupon', 'bank_transfer', 'gift_card'] %}}
115-
116- with orders as (
117-
118- select * from {{ ref('stg_orders') }}
119-
120- ),
121-
122- payments as (
123-
124- select * from {{ ref('stg_payments') }}
125-
126- ),
127-
128- order_payments as (
129-
130- select
131- order_id,
132-
133- {{% for payment_method in payment_methods -%}}
134- sum(case when payment_method = '{{ payment_method }}' then amount else 0 end) as {{ payment_method }}_amount,
135- {{% endfor -%}}
136-
137- sum(amount) as total_amount
138-
139- from payments
140-
141- group by order_id
142-
143- ),
144-
145- final as (
146-
147- select
148- orders.order_id,
149- orders.customer_id,
150- orders.order_date,
151- orders.status,
152-
153- {{% for payment_method in payment_methods -%}}
154-
155- order_payments.{{ payment_method }}_amount,
156-
157- {{% endfor -%}}
158-
159- order_payments.total_amount as amount
160-
161- from orders
162-
163-
164- left join order_payments
165- on orders.order_id = order_payments.order_id
166-
167- )
168-
169- select * from final
170- """ # noqa: N806
171- LOAD_TEST_SIZE = 1000 # noqa: N806
172-
173- print ("\n " , "=" * 20 , "\n " )
174- print ("TEST /compile" )
175- t1 = time .perf_counter ()
176- futs = e .map (
177- lambda i : client .post (
178- "/compile" ,
179- params = f"--> select {{{{ 1 + { i } }}}} \n { STATEMENT } " ,
180- headers = {"X-dbt-Project" : random .choice (PROJECTS )},
181- content_type = "text/plain" ,
182- ),
183- range (LOAD_TEST_SIZE ),
184- )
185- print ("All Successful:" , all (futs ))
186- t2 = time .perf_counter ()
187- print (
188- (t2 - t1 ) / LOAD_TEST_SIZE ,
189- (
190- f"seconds per `/compile` across { LOAD_TEST_SIZE } calls from"
191- f" { SIMULATED_CLIENTS } simulated clients randomly distributed between"
192- f" { len (PROJECTS )} different projects with a sql statement of ~{ len (STATEMENT )} chars"
193- ),
194- )
195-
196- print ("\n " , "=" * 20 , "\n " )
197- print ("TEST /run" )
198- t1 = time .perf_counter ()
199- futs = e .map (
200- lambda i : client .post (
201- "/run" ,
202- params = f"-->> select {{{{ 1 + { i } }}}} \n { STATEMENT } " ,
203- headers = {"X-dbt-Project" : random .choice (PROJECTS )},
204- content_type = "text/plain" ,
205- ),
206- range (LOAD_TEST_SIZE ),
207- )
208- print ("All Successful:" , all (futs ))
209- t2 = time .perf_counter ()
210- print (
211- (t2 - t1 ) / LOAD_TEST_SIZE ,
212- (
213- f"seconds per `/run` across { LOAD_TEST_SIZE } calls from { SIMULATED_CLIENTS } simulated"
214- f" clients randomly distributed between { len (PROJECTS )} different projects with a sql"
215- f" statement of ~{ len (STATEMENT )} chars"
216- ),
217- )
218-
219- e .shutdown (wait = True )
0 commit comments