I am using Mocha to test a Sails application. I have 2 test files. Both test files do the standard Before/After Sails.lift and Sails.lower.
When I run mocha test/TestDataEntry.js and mocha test/TestEventEntry separately, they execute properly. If I run just mocha, test/TestDataEntry executes properly but test/TestEventEntry fails. It seems as if the Sails server is not cycling down and up properly. Any suggestions for handling this issue would be appreciated. The terminal output is as follows:
larry#larry-Aspire-M3985 ~/Projects/web-backend $ mocha
Data Entry testing:
sails lifted
✓ bad url
✓ bad device (91ms)
✓ expired token (61ms)
✓ bad packet: missing Data field (59ms)
✓ bad packet: Data is not an array (62ms)
✓ bad packet: Data is empty (60ms)
✓ bad packet: missing data field D2 (60ms)
✓ bad packet: missing data field D1 (62ms)
✓ bad packet: missing data field TS (61ms)
✓ bad packet: bad timestamp field (64ms)
✓ good packet (60ms)
sails down
Event Entry testing:
sails lifted
✓ bad url
1) bad device
double callback!
2) expired token
double callback!
3) bad packet: missing Data field
double callback!
4) bad packet: Data is not an array
double callback!
5) bad packet: Data is empty
double callback!
6) bad packet: missing data field ED
double callback!
7) bad packet: missing data field ET
double callback!
8) bad packet: missing data field TS
double callback!
9) bad packet: bad timestamp field
double callback!
10) good packet
double callback!
sails down
12 passing (2s)
10 failing
1) Event Entry testing: bad device:
Uncaught AssertionError: expected [Error: connect ECONNREFUSED] to be null
2) Event Entry testing: expired token:
Uncaught AssertionError: expected [Error: connect ECONNREFUSED] to be null
3) Event Entry testing: bad packet: missing Data field:
Uncaught AssertionError: expected [Error: connect ECONNREFUSED] to be null
4) Event Entry testing: bad packet: Data is not an array:
Uncaught AssertionError: expected [Error: connect ECONNREFUSED] to be null
5) Event Entry testing: bad packet: Data is empty:
Uncaught AssertionError: expected [Error: connect ECONNREFUSED] to be null
6) Event Entry testing: bad packet: missing data field ED:
Uncaught AssertionError: expected [Error: connect ECONNREFUSED] to be null
7) Event Entry testing: bad packet: missing data field ET:
Uncaught AssertionError: expected [Error: connect ECONNREFUSED] to be null
8) Event Entry testing: bad packet: missing data field TS:
Uncaught AssertionError: expected [Error: connect ECONNREFUSED] to be null
9) Event Entry testing: bad packet: bad timestamp field:
Uncaught AssertionError: expected [Error: connect ECONNREFUSED] to be null
10) Event Entry testing: good packet:
Uncaught AssertionError: expected [Error: connect ECONNREFUSED] to be null
The following is the Before/After code:
before(function (done) {
// Lift Sails and start the server
Sails.lift({
log: {
level: 'error'
}
}, function (err, sails) {
console.log("sails lifted");
done();
});
});
after(function (done) {
console.log('sails down');
Sails.lower(done);
});
OK, it turns out that there is an anonymous parent describe block that is the parent of all of the test file describe blocks. So if a before/after hook is introduced at the anonymous parent level, then it covers all of the test files as a group.
Mocha executes the test files in alphabetical order by default. So I have constructed a test file 'aaaa.js' that only contains the before/after lifting and lowering of Sails. This introduces the before/after hooks at the parent level.
Now, 'mocha' executes all of the test files in test/* without a problem. The only drawback to this approach is that I no longer have the before/after hooks in the individual test files and therefore must use: 'mocha test/aaaa.js test/TestDataEntry.js' to ensure that Sails is lifted and lowered properly.
An approach to run multiple mocha tests with sails is to spawn a new sails instance for each mocha test
var SailsApp = require('sails').Sails;
describe('MochaTest',function() {
var sails = new SailsApp();
before(function(done) {
sails.lift({},
function(err,server) {
if(err) {
done(err);
} else {
done(err,sails);
}
});
});
after(function(done) {
sails.lower(done);
});
});
Related
I'm using the Solana package with Jupiter swap token. After getting the swap result. I'm executing a transaction synchronously with the Solana package sendTransaction method at that time. I'm getting the below error code.
Jupiter Swagger collection.
{accounts: null, err: {InstructionError: [0, {Custom: 3012}]}, logs: [Program JUP3c2Uh3WA4Ng34tw6kPd2G4C5BB21Xo36Je1s32Ph invoke [1], Program log: Instruction: SetTokenLedger, Program log: AnchorError caused by account: token_account. Error Code: AccountNotInitialized. Error Number: 3012. Error Message: The program expected this account to be already initialized., Program JUP3c2Uh3WA4Ng34tw6kPd2G4C5BB21Xo36Je1s32Ph consumed 5139 of 600000 compute units, Program JUP3c2Uh3WA4Ng34tw6kPd2G4C5BB21Xo36Je1s32Ph failed: custom program error: 0xbc4], unitsConsumed: 0}
Jupiter can create up to 3 transactions (setupTransaction, swapTransaction, cleanupTransaction). Make sure that you execute all of them (if they are not null) in this order.
i am trying to name my token with metadata but i get this error always.
C:\Users\efeka\Desktop\img\node_modules#solana\web3.js\src\connection.ts:4546
throw new SendTransactionError(
^
SendTransactionError: failed to send transaction: Transaction simulation failed: Error processing Instruction 0: custom program error: 0x7
at Connection.sendEncodedTransaction
(C:\Users\efeka\Desktop\img\node_modules#solana\web3.js\src\connection.ts:4546:13)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async Connection.sendRawTransaction
(C:\Users\efeka\Desktop\img\node_modules#solana\web3.js\src\connection.ts:4505:20)
at async Connection.sendTransaction
(C:\Users\efeka\Desktop\img\node_modules#solana\web3.js\src\connection.ts:4493:12)
at async Object.sendAndConfirmTransaction
(C:\Users\efeka\Desktop\img\node_modules#solana\web3.js\src\util\send-and-confirm-transaction.ts:31:21)
at async main (C:\Users\efeka\Desktop\img\name.ts:62:18) {
logs: [
'Program metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s invoke [1]',
'Program log: Instruction: Update Metadata Accounts v2',
'Program log: Update Authority given does not match',
'Program metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s consumed 5855 of 200000 compute units',
'Program metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s failed: custom program error: 0x7'
]
}
I didnt create token now, i created my token before 1 year. I think i didnt authorize my token or wallet.
When I watch the certain ids in the collection using MongoDB watch I am getting error
ERROR Error: Uncaught (in promise): e: (TRANSPORT_ERROR): the request transport encountered an error communicating with Stitch: event source failed to open and will not reconnect; check network log for more details
e: (TRANSPORT_ERROR): the request transport encountered an error communicating with Stitch: event source failed to open and will not reconnect; check network log for more details
It was working till yesterday it started from today
const db = mongoClient.db(environment.databaseName);
const comments = db.collection('collectionName');
this.changeStream = await comments.watch(ids);
this.changeStream.onNext((event) => {
console.log('Watched document changed:', event);
this.fetchData();
});
I expect that whenever the document is changed in the list of ids. Change event should trigger.
This indicates that your app is unable to communicate with the stitch backend, probably because of not internet or poor network
I am having a somewhat reproducible problem on a Swift server I'm running. This is a multi-threaded server, using Kitura. The basics are: After the server has been running for a period of time, download requests start needing retries from the client (usually three retries). The attempts from the client result in the server thread not terminating. On the server, the download problem shows up like this in the log:
[INFO] REQUEST /DownloadFile: ABOUT TO END ...
And then the request never terminates.
The relevant fragment code in my server looks like this:
// <snip>
Log.info(message: "REQUEST \(request.urlURL.path): ABOUT TO END ...")
do {
try self.response.end()
Log.info(message: "REQUEST \(request.urlURL.path): STATUS CODE: \(response.statusCode)")
} catch (let error) {
Log.error(message: "Failed on `end` in failWithError: \(error.localizedDescription); HTTP status code: \(response.statusCode)")
}
Log.info(message: "REQUEST \(request.urlURL.path): COMPLETED")
// <snip>
That is, the server clearly seems to hang on the call to end (a Kitura method). See also https://github.com/crspybits/SyncServerII/blob/master/Sources/Server/Setup/RequestHandler.swift#L105
Immediately before this issue came up last time, I observed the following in my server log:
[2017-07-12T15:31:23.302Z] [ERROR] [HTTPServer.swift:194 listen(listenSocket:socketManager:)] Error accepting client connection: Error code: 5(0x5), ERROR: SSL_accept, code: 5, reason: DH lib
[2017-07-12T15:31:23.604Z] [ERROR] [HTTPServer.swift:194 listen(listenSocket:socketManager:)] Error accepting client connection: Error code: 1(0x1), ERROR: SSL_accept, code: 1, reason: Could not determine error reason.
[2017-07-12T15:31:23.995Z] [ERROR] [HTTPServer.swift:194 listen(listenSocket:socketManager:)] Error accepting client connection: Error code: 1(0x1), ERROR: SSL_accept, code: 1, reason: Could not determine error reason.
[2017-07-12T15:40:32.941Z] [ERROR] [HTTPServer.swift:194 listen(listenSocket:socketManager:)] Error accepting client connection: Error code: 1(0x1), ERROR: SSL_accept, code: 1, reason: Could not determine error reason.
[2017-07-12T15:42:43.000Z] [VERBOSE] [HTTPServerRequest.swift:215 parsingCompleted()] HTTP request from=139.162.78.135; proto=https;
[INFO] REQUEST RECEIVED: /
[2017-07-12T16:32:38.479Z] [ERROR] [HTTPServer.swift:194 listen(listenSocket:socketManager:)] Error accepting client connection: Error code: 1(0x1), ERROR: SSL_accept, code: 1, reason: Could not determine error reason.
I am not sure where this is coming from in the sense that I'm not sure if one of my client's is generating this. I do not explicitly make requests to my server with "/". (I do occasionally see requests made to my server from clients that are not mine-- it is possible this is one of these). Note that all except one of these log messages are coming from Kitura, not directly from my code. My log message is [INFO] REQUEST RECEIVED: /.
If I was a betting man, I'd say the above errors put my server into a state where afterwards, I see this download/retry behavior.
My only solution at this point is to restart the server. From which point the issue doesn't immediately happen.
Thoughts?
I'm not sure if this addresses the root problem, or if it's just a work-around, but it appears to be working. With the server as stated in the question, I had been using Kitura's built-in SSL support. I have now switched to using NGINX as a front-end, and no longer use Kitura's built-in SSL support. NGINX takes care of all the HTTPS/SSL details. Since doing this (about a month ago), and with the server running for all of that intervening time, I have not experience the not terminating issue reported in this question. See also https://github.com/crspybits/SyncServerII/issues/28
when recived the answer from MongoDB, know that my error is a duplicate key but why status=500 ?, it should be 4**.
I'm using nodejs (sails/express.js)
{ "error": {
"error": "E_UNKNOWN",
"status": 500,
"summary": "Encountered an unexpected error",
"raw": {
"name": "MongoError",
"code": 11000,
"err": "E11000 duplicate key error index: eReporterDB.users.$name_1 dup key: { : \"codin\" }"
} } }
the answer is here for nodejs
Operational errors vs. programmer errors
It's helpful to divide all errors into two broad categories:
Operational errors represent run-time problems experienced by correctly-written programs. These are not bugs in the program. In
fact, these are usually problems with something else: the system
itself (e.g., out of memory or too many open files), the system's
configuration (e.g., no route to a remote host), the network (e.g.,
socket hang-up), or a remote service (e.g., a 500 error, failure to
connect, or the like). Examples include:
failed to connect to server
failed to resolve hostname
**invalid user input**
request timeout
server returned a 500 response
socket hang-up
system is out of memory
Programmer errors are bugs in the program. These are things that can always be avoided by changing the code. They can never be handled
properly (since by definition the code in question is broken).
tried to read property of "undefined"
called an asynchronous function without a callback
passed a "string" where an object was expected
passed an object where an IP address string was expected