Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
Mynij-unit-tests
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Alexandra Rogova
Mynij-unit-tests
Commits
91e4e40b
Commit
91e4e40b
authored
Oct 22, 2019
by
Alexandra Rogova
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
index building and saving time test
parent
96bd16ab
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
164 additions
and
0 deletions
+164
-0
time_index.js
time_index.js
+64
-0
time_index_random.js
time_index_random.js
+100
-0
No files found.
time_index.js
0 → 100644
View file @
91e4e40b
const
puppeteer
=
require
(
'
puppeteer
'
);
const
Server
=
require
(
'
ws
'
).
Server
;
const
args
=
require
(
"
yargs
"
)
.
usage
(
"
Usage : load_index.js -saveAs metadata/attachment -file file_path
"
)
.
demandOption
([
'
file
'
])
.
demandOption
([
'
saveAs
'
])
.
alias
(
"
f
"
,
"
file
"
)
.
alias
(
"
s
"
,
"
saveAs
"
)
.
describe
(
"
file
"
,
"
file containing content to put in the index, data must follow the CSV standard
"
)
.
describe
(
"
saveAs
"
,
"
choose whether to save the index as metadata or attachments in the indexeddb
"
)
.
nargs
(
"
file
"
,
1
)
.
nargs
(
"
saveAs
"
,
1
)
.
argv
;
if
(
!
(
args
.
saveAs
===
"
metadata
"
||
args
.
saveAs
===
"
attachment
"
)){
throw
'
Unrecognized save as argument
'
;
}
var
saveAs
=
args
.
saveAs
,
browser
,
page
,
adding_start
,
adding_total
,
saving_start
,
saving_total
;
function
init_server
(){
var
port
=
9030
;
var
ws
=
new
Server
({
port
:
port
});
ws
.
on
(
'
connection
'
,
function
(
w
){
w
.
on
(
'
message
'
,
function
(
msg
){
if
(
msg
===
"
started adding
"
){
adding_start
=
Date
.
now
();
}
else
if
(
msg
===
"
started saving
"
){
adding_total
=
Date
.
now
()
-
adding_start
;
saving_start
=
Date
.
now
();
}
else
if
(
msg
===
"
finished saving
"
){
saving_total
=
Date
.
now
()
-
saving_start
;
console
.
log
(
"
Time spent :
"
);
console
.
log
(
"
Adding :
"
+
adding_total
/
1000
+
"
s
"
);
console
.
log
(
"
Saving :
"
+
saving_total
/
1000
+
"
s
"
);
browser
.
close
();
}
else
{
console
.
log
(
"
Error :
"
+
msg
);
browser
.
close
();
}
});
w
.
on
(
'
close
'
,
function
()
{
ws
.
close
();
});
});
}
(
async
()
=>
{
init_server
();
browser
=
await
puppeteer
.
launch
();
page
=
await
browser
.
newPage
();
await
page
.
goto
(
'
https://softinst115787.host.vifib.net/public/unit_tests/time_index.html?saveAs=
'
+
saveAs
);
const
[
fileChooser
]
=
await
Promise
.
all
([
page
.
waitForFileChooser
(),
page
.
click
(
'
input#load
'
)
]);
await
fileChooser
.
accept
([
args
.
file
]);
})();
time_index_random.js
0 → 100644
View file @
91e4e40b
const
randomstring
=
require
(
"
randomstring
"
);
const
tmp
=
require
(
'
tmp
'
);
const
fs
=
require
(
'
fs
'
);
const
puppeteer
=
require
(
'
puppeteer
'
);
const
Server
=
require
(
'
ws
'
).
Server
;
const
args
=
require
(
"
yargs
"
)
.
usage
(
"
Usage : load_index.js -saveAs metadata/attachment -p Number of random paragraphs to generate
"
)
.
demandOption
([
'
saveAs
'
])
.
demandOption
([
'
paragraphs
'
])
.
alias
(
"
p
"
,
"
paragraphs
"
)
.
alias
(
"
s
"
,
"
saveAs
"
)
.
describe
(
"
paragraphs
"
,
"
Number of random paragraphs to generate
"
)
.
describe
(
"
saveAs
"
,
"
choose whether to save the index as metadata or attachments in the indexeddb
"
)
.
nargs
(
"
saveAs
"
,
1
)
.
nargs
(
"
paragraphs
"
,
1
)
.
argv
;
if
(
!
(
args
.
saveAs
===
"
metadata
"
||
args
.
saveAs
===
"
attachment
"
)){
throw
'
Unrecognized save as argument
'
;
}
var
saveAs
=
args
.
saveAs
,
browser
,
page
,
adding_start
,
adding_total
,
saving_start
,
saving_total
;
function
gen_rdm_string
(
length
){
return
randomstring
.
generate
({
length
:
length
,
charset
:
'
alphabetic
'
});
}
function
gen_rdm_sentence
(
word_count
,
word_length
){
var
tmp_word_array
=
[];
for
(
var
i
=
0
;
i
<
word_count
;
i
+=
1
){
tmp_word_array
[
i
]
=
gen_rdm_string
(
word_length
);
}
return
tmp_word_array
.
join
(
"
"
);
}
function
gen_rdm_paragraph
(
sentence_count
,
words_per_sentence
,
word_length
){
var
tmp_sentence_array
=
[];
for
(
var
i
=
0
;
i
<
sentence_count
;
i
+=
1
){
tmp_sentence_array
[
i
]
=
gen_rdm_sentence
(
words_per_sentence
,
word_length
);
}
return
tmp_sentence_array
.
join
(
"
.
"
);
}
function
init_server
(){
var
port
=
9030
;
var
ws
=
new
Server
({
port
:
port
});
ws
.
on
(
'
connection
'
,
function
(
w
){
w
.
on
(
'
message
'
,
function
(
msg
){
if
(
msg
===
"
started adding
"
){
adding_start
=
Date
.
now
();
}
else
if
(
msg
===
"
started saving
"
){
adding_total
=
Date
.
now
()
-
adding_start
;
saving_start
=
Date
.
now
();
}
else
if
(
msg
===
"
finished saving
"
){
saving_total
=
Date
.
now
()
-
saving_start
;
console
.
log
(
"
Time spent :
"
);
console
.
log
(
"
Adding :
"
+
adding_total
/
1000
+
"
s
"
);
console
.
log
(
"
Saving :
"
+
saving_total
/
1000
+
"
s
"
);
browser
.
close
();
}
else
{
console
.
log
(
"
Error :
"
+
msg
);
browser
.
close
();
}
});
w
.
on
(
'
close
'
,
function
()
{
ws
.
close
();
});
});
}
function
gen_random_content
(){
var
tmp_para_array
=
[];
for
(
var
i
=
0
;
i
<
args
.
p
;
i
+=
1
){
tmp_para_array
[
i
]
=
gen_rdm_paragraph
(
6
,
15
,
5
);
}
var
tmp_file
=
tmp
.
fileSync
();
fs
.
writeFileSync
(
tmp_file
.
name
,
tmp_para_array
.
join
(
"
\n
"
));
return
tmp_file
.
name
;
}
(
async
()
=>
{
init_server
();
var
file_path
=
gen_random_content
();
browser
=
await
puppeteer
.
launch
();
page
=
await
browser
.
newPage
();
await
page
.
goto
(
'
https://softinst115787.host.vifib.net/public/unit_tests/time_index.html?saveAs=
'
+
saveAs
);
const
[
fileChooser
]
=
await
Promise
.
all
([
page
.
waitForFileChooser
(),
page
.
click
(
'
input#load
'
)
]);
await
fileChooser
.
accept
([
file_path
]);
})();
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment