@@ -4,6 +4,16 @@ use std::{fmt::Debug, future::Future, hash::Hash};
4
4
use n0_future:: { future, FuturesUnordered } ;
5
5
use tokio:: sync:: { mpsc, oneshot} ;
6
6
7
+ /// Trait to reset an entity state in place.
8
+ ///
9
+ /// In many cases this is just assigning the default value, but e.g. for an
10
+ /// `Arc<Mutex<T>>` resetting to the default value means an allocation, whereas
11
+ /// reset can be done without.
12
+ pub trait Reset : Default {
13
+ /// Reset the state to its default value.
14
+ fn reset ( & mut self ) ;
15
+ }
16
+
7
17
#[ derive( Debug , Clone , Copy , PartialEq , Eq ) ]
8
18
pub enum ShutdownCause {
9
19
/// The entity is shutting down gracefully because the entity is idle.
@@ -373,7 +383,7 @@ mod main_actor {
373
383
match e {
374
384
mpsc:: error:: TrySendError :: Full ( cmd) => {
375
385
let entity_actor:: Command :: Spawn ( spawn) = cmd else {
376
- panic ! ( )
386
+ unreachable ! ( )
377
387
} ;
378
388
warn ! (
379
389
"Entity actor inbox is full, cannot send command to entity actor {:?}." ,
@@ -385,7 +395,7 @@ mod main_actor {
385
395
}
386
396
mpsc:: error:: TrySendError :: Closed ( cmd) => {
387
397
let entity_actor:: Command :: Spawn ( spawn) = cmd else {
388
- panic ! ( )
398
+ unreachable ! ( )
389
399
} ;
390
400
error ! (
391
401
"Entity actor inbox is closed, cannot send command to entity actor {:?}." ,
@@ -945,8 +955,9 @@ mod tests {
945
955
for id in values. keys ( ) {
946
956
let log = global. log . get ( id) . unwrap ( ) ;
947
957
if log. len ( ) % 2 != 0 {
948
- println ! ( "{log:#?}" ) ;
949
- panic ! ( "Log for entity {id} must contain an even number of events" ) ;
958
+ panic ! (
959
+ "Log for entity {id} must contain an even number of events.\n {log:#?}"
960
+ ) ;
950
961
}
951
962
for ( i, ( event, _) ) in log. iter ( ) . enumerate ( ) {
952
963
assert_eq ! (
@@ -1307,193 +1318,6 @@ mod tests {
1307
1318
. expect ( "Test failed" ) ;
1308
1319
}
1309
1320
1310
- #[ test]
1311
- fn counter_manager_case_1 ( ) {
1312
- let entries: Vec < ( u64 , u128 ) > = vec ! [
1313
- (
1314
- 18388365709074834514 ,
1315
- 194444835943844072850826645853183303049 ,
1316
- ) ,
1317
- ( 960158425716839792 , 70550702232084465071825242386427394095 ) ,
1318
- ( 3186873658602636868 , 148188033569534503124640136521127325068 ) ,
1319
- (
1320
- 15841980008467069742 ,
1321
- 151174981689849463642221795624442563542 ,
1322
- ) ,
1323
- (
1324
- 13023338767385866119 ,
1325
- 193238684289181333005049821157294047398 ,
1326
- ) ,
1327
- ( 16098863205515154997 , 80978418781577370901253652214289107284 ) ,
1328
- (
1329
- 15494567123826916198 ,
1330
- 155627092752672738120697133860680193469 ,
1331
- ) ,
1332
- ( 5977791771239323572 , 123472069275349355161383651481886216632 ) ,
1333
- (
1334
- 13052414105389926722 ,
1335
- 131961256616178196923794330816338585046 ,
1336
- ) ,
1337
- ( 3265887016396946394 , 310496101037658730275516655380984358257 ) ,
1338
- ( 6225591563791670942 , 286677436984807113590349457123804595045 ) ,
1339
- ( 7719654970290070575 , 261360661842631502732458498326060575764 ) ,
1340
- ( 16346812062252468634 , 20400716043115856216887689562958795320 ) ,
1341
- ( 14895994802127672851 , 65044937087750427440151725121831729492 ) ,
1342
- (
1343
- 13867149684135690908 ,
1344
- 251366416673854856023601420456388852782 ,
1345
- ) ,
1346
- ( 13198762185366773363 , 16049497253389531856433290782978461866 ) ,
1347
- ( 15662018632505153162 , 80545892061421306362192535611401208653 ) ,
1348
- (
1349
- 10904741085833535475 ,
1350
- 317619745773233937506743252527124191472 ,
1351
- ) ,
1352
- ( 9659369546555131509 , 320745667028802630937237317954626404036 ) ,
1353
- ( 9587720266200277507 , 53717910536324979289331387490265657851 ) ,
1354
- ( 4520474546171085081 , 167298150261458948825809210629580417056 ) ,
1355
- ( 16317689018231234032 , 56904692996624675090815630807576954277 ) ,
1356
- ( 1145020483821164407 , 62208025549090848844487296478186250150 ) ,
1357
- ( 12275840731881721168 , 91306991379847803048964981673487745749 ) ,
1358
- ( 4420042860659089062 , 273964008846252634637821526029408158951 ) ,
1359
- ( 6122064752200521014 , 318781380881508640367600316004018858292 ) ,
1360
- (
1361
- 18331791613663867073 ,
1362
- 244797279528173449608649865877521898679 ,
1363
- ) ,
1364
- (
1365
- 12536131143448721128 ,
1366
- 118936654309826194076792135199593582814 ,
1367
- ) ,
1368
- (
1369
- 10871411965855657987 ,
1370
- 217312065385902682099626586116718936639 ,
1371
- ) ,
1372
- (
1373
- 10961019520920546084 ,
1374
- 194969590260788153365214695605968172735 ,
1375
- ) ,
1376
- ( 465341043682902302 , 313210447970957224597900277640449786169 ) ,
1377
- ( 1930531913153049005 , 191839680217418490007545636458005832918 ) ,
1378
- ( 17610861271281749389 , 2158112867473280423584106075388203148 ) ,
1379
- ( 7152124269848448741 , 136954811775819110432364454487364326065 ) ,
1380
- ( 1568989979285654655 , 20222353298755466913838704346056341244 ) ,
1381
- ( 7965349575514397114 , 289787046147370952383585129455974538147 ) ,
1382
- ( 4190853641474855654 , 252661458083167852070830937806141596795 ) ,
1383
- ( 15998503947870046493 , 64060435197012338872019450356958606700 ) ,
1384
- ( 13026276258592007494 , 19335529647117235114474075201115024719 ) ,
1385
- ( 8441510215020513967 , 280188261773078012965811787866560404361 ) ,
1386
- (
1387
- 10888572289604438016 ,
1388
- 107801275926977255088182396292810389978 ,
1389
- ) ,
1390
- ( 8028792684930056950 , 279265463046144709574860584412295388880 ) ,
1391
- (
1392
- 16285632686692032678 ,
1393
- 173211331899082901582219216760818084141 ,
1394
- ) ,
1395
- ( 4252535566180812551 , 26342932911822612391116163156475293693 ) ,
1396
- (
1397
- 13804628128928961483 ,
1398
- 284154599974337978388128510231757620390 ,
1399
- ) ,
1400
- ( 8546188891118395704 , 10518169822941605468924627069322563371 ) ,
1401
- ( 15103555168237341487 , 65242721972208308766038820838106150898 ) ,
1402
- (
1403
- 10178269157159463595 ,
1404
- 192339869053417790279388173311883453342 ,
1405
- ) ,
1406
- ( 4581403777792509197 , 14776646444861423261575214657678462007 ) ,
1407
- (
1408
- 16380082972821908840 ,
1409
- 171941200656585174471984020218050726276 ,
1410
- ) ,
1411
- ( 1264309960451701386 , 134493939272359117017871860428297927223 ) ,
1412
- (
1413
- 14979589892199220502 ,
1414
- 111589155031018603387685907617392369538 ,
1415
- ) ,
1416
- ( 17242367228189069279 , 72930121541745954198212835929591900203 ) ,
1417
- ( 8121456326821108294 , 66979609476744620710556910365293284684 ) ,
1418
- ( 2007258142204162697 , 251687000354783335205647262458691353893 ) ,
1419
- ( 8737832108509452949 , 220588935218057557435066308484665836550 ) ,
1420
- ( 1633859723143576509 , 136307380230378890472597645690064879661 ) ,
1421
- ( 3631531089628868939 , 117193189302995348875537780371743885092 ) ,
1422
- ( 14116484475174217773 , 54047184398246577478804256478007223219 ) ,
1423
- ( 3958875956249588345 , 245230852280065944767864702369745470693 ) ,
1424
- (
1425
- 13540877093555590901 ,
1426
- 315784456112577256036745768678791135182 ,
1427
- ) ,
1428
- (
1429
- 16806612096618910759 ,
1430
- 249546776531613765982448526314333635625 ,
1431
- ) ,
1432
- ( 787606879345898885 , 106585693463551369746522944067316950687 ) ,
1433
- ( 4600372411498679193 , 212195607965427065442095429056450131388 ) ,
1434
- (
1435
- 15549710434033886583 ,
1436
- 123117317137788876226523772665571872625 ,
1437
- ) ,
1438
- ( 18351596054746942123 , 45300934307303895571243742711664551642 ) ,
1439
- ( 4289295596982939716 , 57179935864702088014701622708597340262 ) ,
1440
- (
1441
- 14236340878952223471 ,
1442
- 276513355195514407125503145808612698776 ,
1443
- ) ,
1444
- (
1445
- 16793945091236936234 ,
1446
- 225504874419954047826410211270129372771 ,
1447
- ) ,
1448
- ( 6083434966673351288 , 132608700674916922118081114178409918884 ) ,
1449
- ( 8650928456447960764 , 224830460140536261415627615111659295798 ) ,
1450
- ( 544098001581244681 , 23519946291190733604063394180239868939 ) ,
1451
- ( 6677173915608753908 , 172822575779164355980943891119053877737 ) ,
1452
- ( 9904411679706436478 , 305002806492672706404515108669905493060 ) ,
1453
- ( 3748913669028317014 , 198508895764401149420178353122470259248 ) ,
1454
- ( 18429857739493813163 , 52742680723713620788331716379318053621 ) ,
1455
- (
1456
- 16160446355791350386 ,
1457
- 138122750568611844010694432995073272608 ,
1458
- ) ,
1459
- ( 6546381586950511182 , 211244543160814081913465334374927296227 ) ,
1460
- ( 2141568463796935601 , 208339082504024808729178477691685775704 ) ,
1461
- ( 1557540402694871065 , 123820668511543909640550604769940320362 ) ,
1462
- ( 4806376387020260938 , 242198889246468758028422097703476517279 ) ,
1463
- ( 10572989355971956281 , 10538572317690180019027649199957487191 ) ,
1464
- ( 4419528985467303189 , 241717029481312211533043931115392103679 ) ,
1465
- ( 6026123969772770806 , 107638168362307674120726354668199681855 ) ,
1466
- ( 10446707069162381062 , 8055541720197104310969619867721024782 ) ,
1467
- ( 5775673932884639633 , 78808623784784204136453081044300463180 ) ,
1468
- ( 8334877772954168794 , 247863931114156722743273061049957344581 ) ,
1469
- ( 3268873687286354543 , 295921729987362586985932430782633333103 ) ,
1470
- ( 3966164288731105812 , 168025259063973884714536065035065597041 ) ,
1471
- (
1472
- 11203489126702094930 ,
1473
- 202722625156888049503317726338728149715 ,
1474
- ) ,
1475
- ( 15630106992179578877 , 35009551135670394358942249653897229827 ) ,
1476
- ( 8273535691491394488 , 109976597742540116974717569314107701591 ) ,
1477
- ( 3805901298951698996 , 235306340537276700227769214923480868076 ) ,
1478
- ( 2117742626710589122 , 327739111844587050291636958827184679871 ) ,
1479
- (
1480
- 15269331250753017373 ,
1481
- 319720502694359881891904231590616597459 ,
1482
- ) ,
1483
- ( 6441260656891689190 , 21330291223001965237969254632976565895 ) ,
1484
- ( 7256786238996167073 , 176897044696772200117671096478294494714 ) ,
1485
- ( 12590622778405228523 , 79144381831870004849360854116364256296 ) ,
1486
- ] ;
1487
- let rt = tokio:: runtime:: Builder :: new_multi_thread ( )
1488
- . build ( )
1489
- . expect ( "Failed to create tokio runtime" ) ;
1490
- rt. block_on ( async move {
1491
- let db = mem:: MemDb :: new ( ) ;
1492
- test_random ( db, & entries) . await
1493
- } )
1494
- . expect ( "Test failed" ) ;
1495
- }
1496
-
1497
1321
#[ test_strategy:: proptest]
1498
1322
fn test_counters_manager_proptest_fs ( entries : Vec < ( u64 , u128 ) > ) {
1499
1323
let dir = tempfile:: tempdir ( ) . unwrap ( ) ;
0 commit comments