service-api-smoke.scm 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. ;;; Copyright © 2020 Maxime Devos <maxime.devos@student.kuleuven.be>
  2. ;;; This file is part of rehash.
  3. ;;;
  4. ;;; rehash is free software; you can redistribute it and/or modify it
  5. ;;; under the terms of the GNU General Public License as published by
  6. ;;; the Free Software Foundation; either version 3 of the License, or (at
  7. ;;; your option) any later version.
  8. ;;;
  9. ;;; rehash is distributed in the hope that it will be useful, but
  10. ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
  11. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. ;;; GNU General Public License for more details.
  13. ;;;
  14. ;;; You should have received a copy of the GNU General Public License
  15. ;;; along with rehash. If not, see <http://www.gnu.org/licenses/>.
  16. (use-modules (rehash)
  17. (rehash fibers)
  18. (fibers)
  19. (rehash configuration)
  20. (system foreign)
  21. (srfi srfi-64)
  22. (rnrs base))
  23. ;; TODO
  24. (define (startup)
  25. (system* "gnunet-arm" "-c" "scheme-tests/nonetconf.conf"
  26. "--logfile" "/dev/stdout"
  27. "--start"))
  28. (define (stop)
  29. (system* "gnunet-arm" "-c" "scheme-tests/nonetconf.conf"
  30. "--end"))
  31. (define *test-config* #f)
  32. (define (first-task _)
  33. (define h1 (bytevector->hash HASH_SHA256 #vu8(0 1) 0 2))
  34. (define h2 (bytevector->hash HASH_SHA256 #vu8(2 1) 0 2))
  35. (define s #f)
  36. (define s1 #f)
  37. (define s2 #f)
  38. (define q1 #f)
  39. (startup)
  40. (test-begin "service-api-smoke")
  41. (display "opening connection to rehash service")
  42. (newline)
  43. (set! s (open-rehash-service *test-config*))
  44. (while (not (rehash-service-connected? s))
  45. (display "waiting on rehash service")
  46. (newline)
  47. (sleep 1)
  48. (rehash-service-retry-connect))
  49. (display "done!")
  50. (newline)
  51. ;; FIXME wait until service is up
  52. (set! s1 (store-hash! s h1 h2
  53. #:expiration-time (expt 2 48)
  54. #:anonymity-level 0))
  55. (display "started storing s1!")
  56. (newline)
  57. (set! s2 (store-hash! s h2 h1
  58. #:expiration-time 345678
  59. #:anonymity-level 0))
  60. (display "started storing s2!")
  61. (newline)
  62. ;; todo higher anonymity levels
  63. (store-abort! s1)
  64. (display "stopped storing s1!")
  65. (newline)
  66. (set! q1 (query! s h1 HASH_SHA3_512
  67. #:anonymity-level 0
  68. #:options 0
  69. #:when-found display))
  70. (display "started querying q1!")
  71. (newline)
  72. (store-abort! s2)
  73. (display "stopped storing s2!")
  74. (newline)
  75. (query-abort! q1)
  76. (display "stopped querying s2!")
  77. (newline)
  78. (close-rehash-service s)
  79. (display "closed rehash service")
  80. (test-end "service-api-smoke")
  81. (stop))
  82. (define (main args)
  83. (set! *test-config* (load-configuration "scheme-tests/nonetconf.conf"))
  84. #; (assert (not (null-pointer? *test-config*)))
  85. (run-fibers (lambda ()
  86. (init-fibers-scheduler!)
  87. (start-fibers-scheduler!)
  88. (spawn-fiber
  89. (lambda ()
  90. (do-gnunet-stuff (lambda ()
  91. (first-task #f)))))
  92. ;; give the previous time to complete
  93. ;; TODO
  94. (sleep 10))))
  95. #;(call-with-scheduler *test-config* first-task)