pharo-nosql / mongotalk

A Pharo driver for MongoDB
MIT License
19 stars 13 forks source link

New in-image scripts #67

Closed tinchodias closed 4 years ago

tinchodias commented 4 years ago

Now starting a server is very handy, as this example code shows (available in class side of MongoTestServer):

    "Start"
    server := MongoTestServer new
                port: 27092;
                yourself.
    server start; waitIsWrittable.
    [[  [| isMaster |
        isMaster := server mongoDo: [ :mongo | mongo isMaster ].
        Transcript cr; show: isMaster localTime; cr]
            on: Error do: [ :e | e logCr ].
        1 second wait.
        ] doWhileTrue: [ server isStarted ] ] fork.

    "Play"
    server sigstop. "pause"
    server sigcont. "unpause"

    "Stop"
    server ensureTerminated.

or this code:

replicaSet := MongoTestReplicaSet new
        addMember: 1 port: self mongoUrlA port priority: 5.0;
        addMember: 2 port: self mongoUrlB port priority: 3.0;
        addMember: 3 port: self mongoUrlC port priority: 0.0;
        startAllAndInitiate

(in MongoReplicationTestResources class>>#start)

tinchodias commented 4 years ago

Note about the word "Test" in the MongoTestServer: This class (and MongoTestReplicaSet too) starts "real" mongod instances; I mean, they are not mocks or something like that only useful for testing. I used "Test" because I don't think they can be used with other purposes than creating testing scenarios or benchmarking.

tinchodias commented 4 years ago

I think this PR doesn't hurt anyone. The only limitation I can see is that OSSubprocess doesn't support Windows AFAIK, yet.

tinchodias commented 4 years ago

I discovered a problem with the "initial" changes: Voyage has the "multiple image tests", that install ImageWorker, that install OSProcess (CommandShell project), and it seems to be incompatible to have both in the same image (OSProcess and OSSubprocess).

My motivation to implement these MongoTestServer is to simplify signalling to the mongod processes and simulate in some way errors in replica set servers. The same can be done with OSProcess so... I have push these changes.

tinchodias commented 4 years ago

Any opinion, @estebanlm ?

estebanlm commented 4 years ago

Mmm. MMM... I guess is fine for now. We need to find a way to make OSProcess and OSSubprocess to coexist.

tinchodias commented 4 years ago

Thanks! then I we can merge it.