Skip to content

Commit e0aeb33

Browse files
Correct worker mutex sync primitive tests
1 parent 7909aa4 commit e0aeb33

2 files changed

Lines changed: 15 additions & 47 deletions

File tree

pkg/runtimes/dupher/worker_test.go

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -490,32 +490,16 @@ func ChanParentFlowSpec() {
490490
name: "mutex",
491491
flowName: "MutexParentFlow",
492492
source: map[string]string{
493-
"childmutexa.ds.go": `package main
493+
"childmutex.ds.go": `package main
494494
495495
import (
496496
"github.com/RainingComputers/deepslate/prelude"
497497
"sync"
498498
)
499499
500-
func ChildMutexFlowASpec(mu sync.Mutex, ch chan int) {
500+
func ChildMutexFlowSpec(mu sync.Mutex, ch chan int) {
501501
mu.Lock()
502-
requestData, err := prelude.HttpListen("POST", "/mutex_child_a")
503-
_ = err
504-
_ = requestData
505-
ch <- 1
506-
mu.Unlock()
507-
}
508-
`,
509-
"childmutexb.ds.go": `package main
510-
511-
import (
512-
"github.com/RainingComputers/deepslate/prelude"
513-
"sync"
514-
)
515-
516-
func ChildMutexFlowBSpec(mu sync.Mutex, ch chan int) {
517-
mu.Lock()
518-
requestData, err := prelude.HttpListen("POST", "/mutex_child_b")
502+
requestData, err := prelude.HttpListen("POST", "/mutex_child")
519503
_ = err
520504
_ = requestData
521505
ch <- 1
@@ -529,8 +513,8 @@ import "sync"
529513
func MutexParentFlowSpec() {
530514
var mu sync.Mutex
531515
ch := make(chan int)
532-
go ChildMutexFlowASpec(mu, ch)
533-
go ChildMutexFlowBSpec(mu, ch)
516+
go ChildMutexFlowSpec(mu, ch)
517+
go ChildMutexFlowSpec(mu, ch)
534518
r1 := (<-ch)
535519
r2 := (<-ch)
536520
_ = r1
@@ -543,7 +527,7 @@ func MutexParentFlowSpec() {
543527
{
544528
request: &httpRequest{
545529
method: "POST",
546-
path: "/mutex_child_a",
530+
path: "/mutex_child",
547531
body: "{}",
548532
wantStatus: 200,
549533
},
@@ -552,7 +536,7 @@ func MutexParentFlowSpec() {
552536
{
553537
request: &httpRequest{
554538
method: "POST",
555-
path: "/mutex_child_b",
539+
path: "/mutex_child",
556540
body: "{}",
557541
wantStatus: 200,
558542
},

pkg/runtimes/dython/deepslate/tests/test_worker.py

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -442,31 +442,16 @@ async def chan_parent_flow() -> None:
442442
name="mutex",
443443
flow_name="mutex_parent_flow",
444444
source={
445-
"child_mutex_flow_a.py": """\
445+
"child_mutex_flow.py": """\
446446
from deepslate import dpslio
447447
from deepslate import flow, http_listen, DSError
448448
449449
450450
@flow
451-
async def child_mutex_flow_a(mu: dpslio.Lock, ch: dpslio.Queue[int]):
451+
async def child_mutex_flow(mu: dpslio.Lock, ch: dpslio.Queue[int]):
452452
await mu.acquire()
453453
request_data: bytes | DSError
454-
request_data = http_listen("POST", "/mutex_child_a")
455-
if not isinstance(request_data, bytes):
456-
return request_data
457-
await ch.put(1)
458-
await mu.release()
459-
""",
460-
"child_mutex_flow_b.py": """\
461-
from deepslate import dpslio
462-
from deepslate import flow, http_listen, DSError
463-
464-
465-
@flow
466-
async def child_mutex_flow_b(mu: dpslio.Lock, ch: dpslio.Queue[int]):
467-
await mu.acquire()
468-
request_data: bytes | DSError
469-
request_data = http_listen("POST", "/mutex_child_b")
454+
request_data = http_listen("POST", "/mutex_child")
470455
if not isinstance(request_data, bytes):
471456
return request_data
472457
await ch.put(1)
@@ -475,16 +460,15 @@ async def child_mutex_flow_b(mu: dpslio.Lock, ch: dpslio.Queue[int]):
475460
"mutex_parent_flow.py": """\
476461
from deepslate import dpslio
477462
from deepslate import flow
478-
from .child_mutex_flow_a import child_mutex_flow_a
479-
from .child_mutex_flow_b import child_mutex_flow_b
463+
from .child_mutex_flow import child_mutex_flow
480464
481465
482466
@flow
483467
async def mutex_parent_flow() -> None:
484468
mu: dpslio.Lock = dpslio.Lock()
485469
ch: dpslio.Queue[int] = dpslio.Queue[int]()
486-
dpslio.create_task(child_mutex_flow_a(mu, ch))
487-
dpslio.create_task(child_mutex_flow_b(mu, ch))
470+
dpslio.create_task(child_mutex_flow(mu, ch))
471+
dpslio.create_task(child_mutex_flow(mu, ch))
488472
r1: int = await ch.get()
489473
r2: int = await ch.get()
490474
""",
@@ -495,15 +479,15 @@ async def mutex_parent_flow() -> None:
495479
),
496480
WorkerTestStep(
497481
request=HttpRequest(
498-
method="POST", path="/mutex_child_a", body="{}", want_status=200
482+
method="POST", path="/mutex_child", body="{}", want_status=200
499483
),
500484
),
501485
WorkerTestStep(
502486
sleep=3.0,
503487
),
504488
WorkerTestStep(
505489
request=HttpRequest(
506-
method="POST", path="/mutex_child_b", body="{}", want_status=200
490+
method="POST", path="/mutex_child", body="{}", want_status=200
507491
),
508492
),
509493
WorkerTestStep(

0 commit comments

Comments
 (0)