Skip to content
This repository has been archived by the owner on Nov 8, 2024. It is now read-only.

Writing hooks in other languages e.g. Ruby, Python, PHP, Java, etc.. #134

Closed
netmilk opened this issue Jan 23, 2015 · 7 comments · Fixed by #230
Closed

Writing hooks in other languages e.g. Ruby, Python, PHP, Java, etc.. #134

netmilk opened this issue Jan 23, 2015 · 7 comments · Fixed by #230

Comments

@netmilk
Copy link
Contributor

netmilk commented Jan 23, 2015

I'm curious if it is limiting for anyone to write hooks only in JavaScirpt/CoffeeScript.

Is anyone interested in possibility to write hooks in native language for specific System Under Test? e.g. when my backend is in Rails it could be more comfortable to write hooks in Ruby.

@gonzalo-bulnes
Copy link

Hi @netmilk, I was thinking about that this morning in relation with #100.

In Ruby environments, there are usually resources available that could be used to do the tests setup (e.g. FactoryGirl) and tear down (e.g. DatabaseCleaner). Usually, those resources are themselves tested (e.g. factories validity checking is part of the test suite) and it makes a lot of sense - in my opinion - to use them if possible.

Do you have ideas about how the communication could be established between the Javascript program and support scripts written in other languages?

(I can only imagine a stop/resume mecanism: Dredd runs until there is time to trigger a hook, it stops returning the hook name, the hook then runs and resumes Dredd. But I doesn't seem to be a good idea to me.)

@netmilk
Copy link
Contributor Author

netmilk commented Feb 26, 2015

Hi @gonzalo-bulnes, thank you very much for your ideas. FactoryGirl, DatabaseCleaner and company in other languages are definitely tools which are testing-friendly people used to use and I definitely want to make them available in Dredd envronment.

About bowels inside:
My idea was to use some type of *nix-like inter process communication: signals and named pipes or sockets

When Dredd want to execute some hoook, it will emit JSON with type of hook, compiled HTTP transaction and its name to the pipe and it will wait for the response form hook worker/workers. Worker in some specific language will process all related hooks for passed transaction and after hook execution it will return transaction back to Dredd for execution and/or examination of transaction result.

All ideas, thoughts, improvements, requirements, or contributions are more than welcome! :)

@gonzalo-bulnes
Copy link

I've no idea of how signals, named pipes or sockets work but I'd love to implement the Ruby side of something alike! I'm doing some research.

By the way, pointers are welcome if there is any documentation you specially appreciate on these topics ; )

@gonzalo-bulnes
Copy link

Hi @netmilk,

I did some experiments of inter-process communication with named pipes. Unless I'm missing something, in order to allow Dredd to send the JSON with type of hook, compiled HTTP transaction and its name to the pipe (let's say the hook request) one named pipe should be defined which Dredd could write and the hooks handler could read. And in order to hold the response, another named pipe should be defined which the hooks handler could write and Dredd could read. Am I right?

Now this question: could these two named pipes be provided to Dredd as command-line arguments? (That could be seen as some kind of worker registration.)

# Example: the tmp/dredd_to_worker.pipe can be written by Dredd and
# the tmp/worker_to_dredd.pipe will contain the resulting transaction
# once the hook will be processed
dredd doc/*.apib.md http://localhost:4567 --additional-hooks-handler-input tmp/dredd_to_worker.pipe --additional-hooks-handler-output tmp/worker_to_dredd.pipe

# the flags names are arbitrary and were only chosen to be unambiguous

If they could, then I have an idea about how the communication between Dredd and a Ruby test suite could be implemented (see this example, where the main program would be Dredd, and the worker_provider would be part of a Ruby test suite).

Is that more or less what you had in mind? I'm looking forward for comments : )

Best regards!

@netmilk
Copy link
Contributor Author

netmilk commented Mar 10, 2015

@gonzalo-bulnes,

it's totally cool what you did! I did some investigation about how to figure it out as well and I found out that the most straightforward solution will probably be to use a netowrk socket instead of named pipes. The reason is that node.js doesn't support named pipes, so there is not available mkfifo in node's file module. It would need some workarounds to use pipes in node.js which can be problematic on non-unix platforms and unlike named pipes sockets are fully duplex-capable.

Adam

@gonzalo-bulnes
Copy link

Hi @netmilk,

I'm glad you liked the examples! I'll take a look at sockets, for what I've seen so far, using them instead of pipes sounds right to me. (By the way, note that Ruby doen't support creating named pipes either - at least I didn't found how to create them. Both maned pipes do pre-exist in the examples I wrote.)

Regards!

@netmilk
Copy link
Contributor Author

netmilk commented Mar 17, 2015

Hi @gonzalo-bulnes,

here are some notes about working proof of concept for hooks in Ruby. Let me know what you think, please.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants