integration.rs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. use tracing::info;
  2. use crown::nockapp::test::setup_nockapp;
  3. use crown::nockapp::wire::{SystemWire, Wire};
  4. use crown::noun::slab::NounSlab;
  5. use crown::NockApp;
  6. use sword::noun::{Noun, Slots, D};
  7. use sword_macros::tas;
  8. #[tracing::instrument(skip(nockapp))]
  9. fn run_once(nockapp: &mut NockApp, i: u64) {
  10. info!("before poke construction");
  11. let poke = D(tas!(b"inc")).into();
  12. info!("Poke constructed");
  13. let wire = SystemWire.to_wire();
  14. info!("Wire constructed");
  15. let _ = nockapp.poke_sync(wire, poke).unwrap_or_else(|err| {
  16. panic!(
  17. "Panicked with {err:?} at {}:{} (git sha: {:?})",
  18. file!(),
  19. line!(),
  20. option_env!("GIT_SHA")
  21. )
  22. });
  23. info!("after poke_sync");
  24. let peek: NounSlab = [D(tas!(b"state")), D(0)].into();
  25. // res should be [~ ~ %0 val]
  26. let res = nockapp.peek_sync(peek);
  27. info!("after peek_sync");
  28. let res = res.unwrap_or_else(|err| {
  29. panic!(
  30. "Panicked with {err:?} at {}:{} (git sha: {:?})",
  31. file!(),
  32. line!(),
  33. option_env!("GIT_SHA")
  34. )
  35. });
  36. let root = unsafe { res.root() };
  37. let val: Noun = root.slot(15).unwrap_or_else(|err| {
  38. panic!(
  39. "Panicked with {err:?} at {}:{} (git sha: {:?})",
  40. file!(),
  41. line!(),
  42. option_env!("GIT_SHA")
  43. )
  44. });
  45. unsafe {
  46. assert!(val.raw_equals(&D(i)), "Expected {} but got {:?}", i, val);
  47. }
  48. info!("after raw_equals");
  49. }
  50. // This is just an experimental test to exercise the tracing
  51. // To run this test:
  52. // OTEL_SERVICE_NAME="nockapp_test" RUST_LOG="debug" OTEL_EXPORTER_JAEGER_ENDPOINT=http://localhost:4317 cargo nextest run test_looped_sync_peek_and_poke --nocapture --run-ignored all
  53. #[tokio::test(flavor = "multi_thread", worker_threads = 4)]
  54. #[ignore]
  55. async fn test_looped_sync_peek_and_poke() {
  56. use crown::observability::*;
  57. let subscriber = init_tracing().unwrap_or_else(|err| {
  58. panic!(
  59. "Panicked with {err:?} at {}:{} (git sha: {:?})",
  60. file!(),
  61. line!(),
  62. option_env!("GIT_SHA")
  63. )
  64. });
  65. eprintln!("Use docker compose up to start prometheus and jaeger");
  66. eprintln!("Prometheus dashboard: http://localhost:9090/");
  67. eprintln!("Jaeger dashboard: http://localhost:16686/");
  68. let (_temp, mut nockapp) = setup_nockapp("test-ker.jam").await;
  69. tracing::subscriber::with_default(subscriber, || {
  70. tracing::info!("Starting run_forever");
  71. for i in 1.. {
  72. info!("before run_once");
  73. run_once(&mut nockapp, i);
  74. info!("after run_once");
  75. }
  76. });
  77. }
  78. #[tokio::test]
  79. #[cfg_attr(miri, ignore)]
  80. async fn test_sync_peek_and_poke() {
  81. let (_temp, mut nockapp) = setup_nockapp("test-ker.jam").await;
  82. tokio::task::spawn_blocking(move || {
  83. for i in 1..4 {
  84. let poke = D(tas!(b"inc")).into();
  85. let wire = SystemWire.to_wire();
  86. let _ = nockapp.poke_sync(wire, poke).unwrap_or_else(|err| {
  87. panic!(
  88. "Panicked with {err:?} at {}:{} (git sha: {:?})",
  89. file!(),
  90. line!(),
  91. option_env!("GIT_SHA")
  92. )
  93. });
  94. let peek: NounSlab = [D(tas!(b"state")), D(0)].into();
  95. // res should be [~ ~ %0 val]
  96. let res = nockapp.peek_sync(peek);
  97. let res = res.unwrap_or_else(|err| {
  98. panic!(
  99. "Panicked with {err:?} at {}:{} (git sha: {:?})",
  100. file!(),
  101. line!(),
  102. option_env!("GIT_SHA")
  103. )
  104. });
  105. let root = unsafe { res.root() };
  106. let val: Noun = root.slot(15).unwrap_or_else(|err| {
  107. panic!(
  108. "Panicked with {err:?} at {}:{} (git sha: {:?})",
  109. file!(),
  110. line!(),
  111. option_env!("GIT_SHA")
  112. )
  113. });
  114. unsafe {
  115. assert!(val.raw_equals(&D(i)));
  116. }
  117. }
  118. })
  119. .await
  120. .expect("Synchronous test thread failed");
  121. }