有没有快速检查 Happstack.State 方法的好方法?

发布于 2024-09-04 04:37:01 字数 1004 浏览 2 评论 0原文

我有一组 Happstack.State MACID 方法,我想使用 QuickCheck 对其进行测试,但我无法找出实现该目标的最优雅的方法。我遇到的问题是:

  • 评估 Ev monad 计算的唯一方法是通过 queryIO monad 中更新
  • 无法创建纯粹的内存 MACID 存储; 这是设计使然。因此,在 IO monad 中运行意味着每次测试后都会有临时文件需要清理。
  • 除了使用状态的 initialValue 之外,无法初始化新的 MACID 存储;它不能通过任意生成,除非我公开替换状态批发的访问方法。
  • 解决上述所有问题意味着编写仅使用 MonadReaderMonadState 功能的方法(并在 ReaderState 内运行测试 getEventClockTime 等。

而不是 Ev 这意味着放弃在方法定义中使用 getRandom可以看到的是:

  • 在一次性的磁盘 MACID 存储中运行方法,每次测试后进行清理,并每次都从 initialValue 开始
  • 编写方法以运行大部分代码 。 MonadReaderMonadState (更容易测试),并依赖于其周围的少量不可 QuickCheck 的粘合来调用 getRandomgetEventClockTime 如有必要,

是否有我忽略的更好的解决方案?

I have a set of Happstack.State MACID methods that I want to test using QuickCheck, but I'm having trouble figuring out the most elegant way to accomplish that. The problems I'm running into are:

  • The only way to evaluate an Ev monad computation is in the IO monad via query or update.
  • There's no way to create a purely in-memory MACID store; this is by design. Therefore, running things in the IO monad means there are temporary files to clean up after each test.
  • There's no way to initialize a new MACID store except with the initialValue for the state; it can't be generated via Arbitrary unless I expose an access method that replaces the state wholesale.
  • Working around all of the above means writing methods that only use features of MonadReader or MonadState (and running the test inside Reader or State instead of Ev. This means forgoing the use of getRandom or getEventClockTime and the like inside the method definitions.

The only options I can see are:

  • Run the methods in a throw-away on-disk MACID store, cleaning up after each test and settling for starting from initialValue each time.
  • Write the methods to have most of the code run in a MonadReader or MonadState (which is more easily testable), and rely on a small amount of non-QuickCheck-able glue around it that calls getRandom or getEventClockTime as necessary.

Is there a better solution that I'm overlooking?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

逆蝶 2024-09-11 04:37:01

您可以查看 happstack-state 中包含的快速检查属性:

http://patch-tag.com/r/mae/happstack/snapshot/current/content/pretty/happstack-state/tests/Happstack/State/Tests

如果您只是在进行测试,并且想要一次性数据存储,那么您可以使用内存保护程序,它仅将状态、事件文件和检查点存储在 RAM 中。如果你失去了权力,那么你的一切状态都会消失。这对于测试来说很好,但对于真正的实时服务器来说就不行了。您链接到的那条消息谈论的是真实的实时服务器,而不仅仅是测试。

这对解决初始值问题没有帮助,但它确实使选项 1 更容易,因为您不必进行任何磁盘清理。

要替换初始值,您需要创建自己的方法来替换当前状态批发。

像:

newState :: YourState -> Update YourState ()
newState st = put st

或者什么的。

  • 杰里米

You might checkout out the quickcheck properties that are included with happstack-state:

http://patch-tag.com/r/mae/happstack/snapshot/current/content/pretty/happstack-state/tests/Happstack/State/Tests

If you are just doing testing, and you want a throw-away data store, then you can use the memory saver, which just stores the state, event files, and checkpoints in RAM. If you lose power, then all your state would be lost. That is fine for tests, but not for a real live server. That message you linked to was talk about real live servers, not just testing.

That won't help with the initialValue issue, but it does make option 1 easier since you don't have to do any disk cleanup.

To replace the initialValue, you would need to create your own method that replaces the current state wholesale.

something like:

newState :: YourState -> Update YourState ()
newState st = put st

or something.

  • jeremy
千里故人稀 2024-09-11 04:37:01

如果您将函数编写为 MonadState(或用于查询的 MonadReader)上的多态函数,则使用 runState/runReader 设置测试工具会容易得多。

据我所知,happstack TH 代码生成器可以很好地处理这样的签名。

If you write your functions as polymorphic over MonadState (or MonadReader for queries) it can be a lot easier to set up a test harness with runState/runReader.

The happstack TH code generators are fine with signatures like that, from what I remember.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文