how k6 will support for createReadStream property to read file stream - k6

When I am reading the file from its filepath in typescript. I am getting the error that- Object has no member 'statSync' and Object has no member 'createReadStream'.
Below is the code:=
const fs = require('fs');
let filePath:='D:\\Dummy.pdf';
let streamingInput;
if (filePath) {
streamingInput = {
contentLength: fs.statSync(filePath).size,
contentType: contentType,
stream: fs.createReadStream(filePath)
};
return streamingInput;
}

k6 is NOT based on nodejs, as such nodejs standard libraries are not supported and you have probably used browserify (as you should) to get it to work in k6.
But browserify apparently doesn't support statSync or createReadStream.
I would suggest you just use k6's open() which will not stream the contents but instead will read them in memory.
Adding a streaming reader is probably a good idea for big files especially given that currently the contents of the file will have a copy for each VU that k6 has as they run a completely separate JS VM. I will be happy if you can open an issue about this

Related

gCloud: File index.js does not exist in root directory

I am a first time user of Gcloud. When I run the following command:
gcloud beta functions deploy FirstBot --stage-bucket [BUCKET_NAME] --trigger-http
I'm getting this error in my cmd:
ERROR: (gcloud.beta.functions.deploy) OperationError: code=3, message=Function l
oad error: File index.js or function.js that is expected to define function does
n't exist in the root directory.
I have tried 2 index.js files:
Here's no.1:
/*
HTTP Cloud Function.
#param {Object} req Cloud Function request context.
#param {Object} res Cloud Function response context.
*/
exports.FirstBot = function FirstBot (req, res) {
response = "This is a sample response from your webhook!" //Default response from the webhook to show it's working
res.setHeader('Content-Type', 'application/json'); //Requires application/json MIME type
res.send(JSON.stringify({ "speech": response, "displayText": response
//"speech" is the spoken version of the response, "displayText" is the visual version
}));
};
Here's the second one:
/
HTTP Cloud Function.
#param {Object} req Cloud Function request context.
#param {Object} res Cloud Function response context.
*/
exports.helloHttp = function helloHttp (req, res) {
response = "This is a sample response from your webhook!" //Default response from the webhook to show it's working
res.setHeader('Content-Type', 'application/json'); //Requires application/json MIME type
res.send(JSON.stringify({ "speech": response, "displayText": response
//"speech" is the spoken version of the response, "displayText" is the visual version
}));
};
The name of my project is FirstBot.
I have created a bucket also.
The path of my FirstBot folder is C:\FirstBot. The index.js file is inside it.
I am following the tutorial at: https://api.ai/docs/getting-started/basic-fulfillment-conversation
Kindly help..Would be grateful!
Is the file in your .gitignore? If a .gcloudignore isn't specified, the .gitignore is used to ignore files.
Adding an empty .gcloudignore should fix this.
The error can also occur if you're not running the deploy command from the same folder where the index.js is located. I.e. it's just "file not found".
I solved it by installing npm for JavaScript.
You're exceeding the Max deployment size limit. From Resource Limits:
Check the content of your project dir, you may have undesired stuff in there.
Adding a bucket to the project via the console solved it for me.
The command gcloud beta functions deploy FirstBot --stage-bucket [BUCKET_NAME] --trigger-http will deploy a function with name FirstBot by creating zip file with content of the directory from which your ran the command.
For the deployment to work you should:
Run the command when you're in C:\FirstBot, or
Add --source C:\FirstBot to your gcloud invocation to let gcloud know that your source code is in a different directory.
II was having a similar issue and solution for me was pretty easy to apply but hard to find.
In case someone can help. I noticed that my .gcloudignore had this line
#!include:.gitignore
and my .gitignore these two
# Compiled JavaScript files
**/*.js
**/*.js.map
Therefore .js files where being ignored and gcloud could not find index.js.
As i don't want compiled files to be in repository, i ended by removing the include at .gcloudignore and add the specific ignores directly, such as node_modules and sensitive data

how to tell FlowType to ignore some json requires?

I have this kind of code in a ./src folder:
var fs = require('fs')
var config = require("../config.json")
when run flow, it has this error:
var config = require("../config.json")
^^^^^^^^^^^^^^^^^^ ../config.json. Required module not found
to me, that's a valid statement because the final version will be in a folder with that config.json, is there a way to instruct flowtype not checking this type of error?
Thanks
You could make flow ignore all json files by adding the following to your .flowconfig:
[ignore]
.*\.json
If you want the json file to be checked as well, you could use module.name_mapper to map to the location of your json file. Flow automatically checks required json files.
It would looks something like:
module.name_mapper='^\(.*\)\.json$' -> '<PROJECT_ROOT>/path/to/json/files'

XSLT document() relative path resolving to IIS.exe

I have a .NET WebApi project with two files, both of which have been marked as embedded resources and are deployed with the application. The files are also both in the same directory in the deployed application:
./xsl/transform.xslt
./xsl/schema.xsd
The xslt file needs to load the xsd file via the document() function:
<xsl:template match="*[not(local-name() = document('schema.xsd')//xs:element/#name)]" />
<xsl:template match="#*[not(local-name() = document('schema.xsd')//xs:attribute/#name)]" />
Unfortunately, I'm getting an exception at runtime that indicates that the relative path being resolved is the program files directory for IIS and not the directory where transform.xslt is located:
{
"Message": "An error has occurred.",
"ExceptionMessage": "An error occurred while loading document 'schema.xsd'. See InnerException for a complete description of the error.",
"ExceptionType": "System.Xml.Xsl.XslTransformException",
"StackTrace": "<ommitted>"
"InnerException": {
"Message": "An error has occurred.",
"ExceptionMessage": "Could not find file 'C:\\Program Files (x86)\\IIS Express\\schema.xsd'.",
"ExceptionType": "System.IO.FileNotFoundException",
"StackTrace": "<omitted>"
}
}
I don't want to use an absolute path here because I don't want to become overly dependent on the environment the application is deployed into. Is there anyway to force the relative path source from the same directory that transform.xslt is deployed into at runtime?
For reference, the absolute path to the xslt file at runtime was:
C:\\MyFolder\\MyCode\\MyProject\\Web\\bin\\xsl\\transform.xslt
EDIT:
As requested, the following is (roughly) the code that is used to load the xslt from the manifest resource stream and run the transform. This code is unwrapped from several different custom packages to boil it down into core libraries, so don't worry about the stream management. I promise the real code is much safer:
XmlReader input = this.GetInput();
Stream ouput = new MemoryStream(4096);
Stream stream = typeof(ClassUsingTransform).Assembly.GetManifestResourceStream("transform.xslt");
MemoryStream mStream = new MemoryStream(stream.ToByteArray());
var navigator = new XPathDocument(mStream).CreateNavigator();
XslCompiledTransform processor = new XslCompiledTransform();
processor.Load(navigator, XsltSettings.TrustedXslt, new XmlUrlResolver());
processor.Transform(input, new XsltArgumentList(), output);
The XmlUrlResolver could not be unwrapped into builtins easily, but the type used inherited from XmlUrlResolver and didn't appear to modify any of the builtin settings. Most of the work done in the derived classes seemed to focus on performance optimizations. If anyone thinks the implementation here is important, I can try to unwrap that class a bit better.
The XsltArgumentList used was also a derived type, but the argument list is empty as far as I can tell.

Get files from other ftp server into meteor app

I need to find a way to read files from a remote ftp server:
ftp.server.com/path/to/folder
Inside the folder are text files which contain csv data. The data then has to go into the meteor's MongoDB. I can kind of see that it is a problem to do this from the client, because client javascript does not speak FTP. What about the meteor server?
You can use an npm module to do this on the meteor server.
Add the meteorhacks:npm package in. Add the file to the generated packages.json file.
A suggested package would be the https://github.com/mscdex/node-ftp package.
Server side code:
var Client = Meteor.npmRequire("ftp");
var c = new Client();
c.on('ready', function() {
c.list(function(err, list) {
if (err) throw err;
console.dir(list);
c.end();
});
});
// connect to localhost:21 as anonymous
c.connect();

Flex crossdomain.xml not working correctly in Chrome/Firefox?

I've spent quite a bit of time on this so here's where I'm stuck.
I'm using the debug player 10.1 to get an XMLA request from:
http://localhost/dir/blah.swf
to:
http://localhost/olapbin/msblah.dll
This worked fine in the filesystem, but now its on an IIS7 web server.
After a lot of fiddling with the crossdomain.xml file I settled on:
<?xml version="1.0"?>
<cross-domain-policy>
<site-control permitted-cross-domain-policies="master-only"/>
<allow-access-from domain="*" to-ports="*" />
<allow-http-request-headers-from domain="*" headers="*"/>
</cross-domain-policy>
which is placed in:
http://localhost/crossdomain.xml
and read with:
Security.loadPolicyFile("http://localhost:80/crossdomain.xml");
I setup Policy file logging (which helped come up with the above file)
and on IE8 its all working just fine. I get:
OK: Root-level SWF loaded: http://127.0.0.1/akts/ThinSlicerRunner.swf
OK: Policy file accepted: http://localhost/crossdomain.xml
OK: Searching for <allow-access-from> in policy files to authorize data loading from resource at http://localhost/olapbin/msmdpump.dll by requestor from http://127.0.0.1/akts/ThinSlicerRunner.swf
OK: Searching for <allow-http-request-headers-from> in policy files to authorize header sending to URL http://localhost/olapbin/msmdpump.dll by requestor from http://127.0.0.1/akts/ThinSlicerRunner.swf
OK: Request for resource at http://localhost/olapbin/msmdpump.dll by requestor from http://127.0.0.1/akts/ThinSlicerRunner.swf is permitted due to policy file at http://localhost/crossdomain.xml
On Chrome and Firefox I just get:
OK: Root-level SWF loaded: http://localhost/akts/ThinSlicerRunner.swf
OK: Policy file accepted: http://localhost/crossdomain.xml
and nothing else... no attempts to authorize the httpservice requests.
In the main flex error log I get:
*** Security Sandbox Violation ***
Connection to
http://localhost/olapbin/msmdpump.dll
halted - not permitted from http://localhost/akts/ThinSlicerRunner.swf
Which doesn't appear when I run the same thing from IE8.
Any idea what's going on ??
AS REQUESTED... MORE CODE
Main sending request:
var connection:TsConnection = this.__connection;
var token:AsyncToken = new AsyncToken(null);
connection.service.request = this.__curSoapRequest;
var actualToken:AsyncToken = connection.service.send();
__tokenArr.push(actualToken);
var responder:AsyncResponder = new AsyncResponder(resultHandler, faultHandler, actualToken);
__responderArr.push(responder);
actualToken.addResponder(responder);
Connection object highlights:
public function init():void {
//Initialize the service object needed to query the server
this.__service = new HTTPService;
this.__service.method = "POST";
this.__service.contentType = "application/xml";
this.__service.resultFormat = "e4x";
this.__service.headers = getHeaders();
this.__service.url = this.__model.xmlaUrl;
this.__initialized = true;
}
public function get service():HTTPService {
return this.__service;
}
private function getHeaders():Object {
var o:Object = {};
o["SOAPAction"] = '"urn:schemas-microsoft-com:xml-analysis:Discover"';
o["Content-Type"] = "text/xml";
return o;
}
Thanks for your help ... hope this helps others when fixed. ;-)
Shaun
http://www.vidgridz.com/
Thanks for everyone's answers. It was indeed able to be solved in the code
even if it wasn't exactly a true coding problem.
Here is the xml data file I was reading the configuration details from:
<tsConnection>
<dataSource>megan</dataSource>
<database>Adventure Works DW 2008</database>
<cube>Adventure Works</cube>
<xmlaUrl><![CDATA[
http://localhost/olapbin/msmdpump.dll
]]></xmlaUrl>
</tsConnection>
Now on the "localTrusted" or "localWithNetworking" setup, this was working just fine.
It also works on the IE8 Flash player even in "remote".
However, what was happening was that the xmlaUrl was being read as:
\n\rhttp://localhost/olapbin/msmdpump.dll
(with the newline and carriage return at the start)
This is was what was confusing the domain checking and throwing a Sandbox Violation
when run in the "remote" security sandbox.
Of course, my xml should have been better, and maybe put in some ignore white
space processing in the code, but still its quite some bizarre, inconsistent
behavior from the Flash player code in Netscape compatible browsers (10.1.x).
So the final, working solution looks like this:
<tsConnection>
<dataSource>megan</dataSource>
<database>Adventure Works DW 2008</database>
<cube>Adventure Works</cube>
<xmlaUrl><![CDATA[http://localhost/olapbin/msmdpump.dll]]></xmlaUrl>
</tsConnection>
I did become a crossdomain.xml expert in the process though. ;-)
Although, now I don't need the file at all.
Bear it in mind if you see some crazy unexplained Sandbox Violations, check for
white space in your service url.
If your DLL backend service and SWF are served from the same domain, it should be allowed. Nothing in the crossdomain.xml file should apply. You should not have to load the crossdomain file manually either. It sounds like that is what you're trying to do.
I suspect something else is going on with your code.

Resources